:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-strong: #edf2f7;
  --ink: #17202a;
  --muted: #667085;
  --line: #d7dee8;
  --blue: #2166d1;
  --blue-dark: #174a9a;
  --green: #177865;
  --red: #b42318;
  --amber: #b7791f;
  --violet: #6f42c1;
  --radius: 8px;
  --shadow: 0 14px 38px rgba(23, 32, 42, 0.08);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background:
    linear-gradient(180deg, #e9eef5 0, #f4f6f8 320px),
    var(--bg);
  color: var(--ink);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--ink);
  min-height: 38px;
  padding: 0 12px;
  cursor: pointer;
}

button:hover {
  border-color: #9fb2c8;
  background: #f8fafc;
}

.primary-button {
  background: var(--blue);
  border-color: var(--blue);
  color: #fff;
}

.primary-button:hover {
  background: var(--blue-dark);
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 24px;
  line-height: 1;
}

.app-shell {
  width: min(1480px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.app-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 24px;
  align-items: start;
  margin-bottom: 20px;
}

.eyebrow,
.section-kicker {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(30px, 4vw, 52px);
  line-height: 1;
}

h2 {
  font-size: 18px;
}

.clock-panel {
  display: grid;
  grid-column: 1 / -1;
  grid-row: 2;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.settings-button,
.settings-close {
  min-width: 42px;
  white-space: nowrap;
}

.settings-button {
  grid-column: 2;
  grid-row: 1;
  justify-self: end;
  width: 38px;
  min-width: 38px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
}

.header-link {
  color: inherit;
  text-decoration: none;
}

.header-link:hover {
  color: var(--blue);
}

.home-shell {
  max-width: 1080px;
}

.home-header {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: start;
  margin: 56px 0 24px;
}

.home-lead {
  max-width: 620px;
  margin: 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.tool-links {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 14px;
}

.tool-link {
  display: grid;
  gap: 8px;
  min-height: 150px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  text-decoration: none;
  box-shadow: var(--shadow);
}

.tool-link:hover {
  border-color: #9fb2c8;
  transform: translateY(-1px);
}

.tool-link strong {
  font-size: 19px;
}

.tool-link span:last-child {
  color: var(--muted);
  line-height: 1.5;
}

.tool-link-kicker {
  color: var(--blue);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.tool-link.is-pending {
  opacity: 0.68;
  cursor: default;
}

.tool-link.is-pending:hover {
  border-color: var(--line);
  transform: none;
}

.clock-panel span {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.86);
  font-weight: 700;
}

.settings-backdrop {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: start end;
  padding: 24px;
  background: rgba(23, 32, 42, 0.32);
}

.settings-backdrop[hidden] {
  display: none;
}

.settings-panel {
  width: min(520px, 100%);
  max-height: calc(100vh - 48px);
  overflow: auto;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: 0 22px 56px rgba(23, 32, 42, 0.22);
}

.settings-panel-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.settings-list {
  display: grid;
  gap: 10px;
}

.settings-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(150px, auto);
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fafbfd;
}

.settings-item h3 {
  margin: 0;
  font-size: 15px;
}

.settings-item p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.settings-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: end;
}

.settings-item :disabled {
  cursor: not-allowed;
  opacity: 0.7;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 380px;
  gap: 20px;
  align-items: start;
}

.planner,
.tool-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.planner {
  min-width: 0;
  overflow: hidden;
}

.planner-toolbar {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr) auto auto;
  gap: 16px;
  align-items: center;
  padding: 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.add-task-popover {
  position: fixed;
  z-index: 100;
  width: min(380px, calc(100vw - 48px));
  max-height: calc(100vh - 120px);
  overflow-y: auto;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: 0 22px 56px rgba(23, 32, 42, 0.22);
}

.add-task-popover[hidden] {
  display: none;
}

.date-controls,
.view-tabs,
.form-actions,
.set-controls,
.inline-form {
  display: flex;
  gap: 8px;
  align-items: center;
}

.view-tabs {
  border: 1px solid var(--line);
  border-radius: 7px;
  padding: 3px;
  background: var(--surface-strong);
}

.view-tab {
  border: 0;
  background: transparent;
  min-height: 32px;
}

.view-tab.is-active {
  background: var(--surface);
  color: var(--blue);
  box-shadow: 0 1px 2px rgba(23, 32, 42, 0.12);
}

.schedule-view {
  min-height: 640px;
}

.hour-view {
  display: grid;
}

.hour-row {
  display: grid;
  grid-template-columns: 70px minmax(0, 1fr);
  min-height: 58px;
  border-bottom: 1px solid #e6ebf1;
}

.hour-label {
  padding: 10px 12px;
  color: var(--muted);
  font-size: 13px;
  background: #fafbfd;
  border-right: 1px solid #e6ebf1;
}

.hour-slot {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-content: start;
  padding: 8px;
}

.day-view {
  display: grid;
  gap: 10px;
  padding: 16px;
}

.day-empty,
.empty-state {
  display: grid;
  place-items: center;
  min-height: 180px;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  background: #fafbfd;
}

.week-view {
  display: grid;
  grid-template-columns: repeat(7, minmax(142px, 1fr));
  min-height: 640px;
  overflow-x: auto;
}

.week-day {
  min-width: 142px;
  border-right: 1px solid #e6ebf1;
}

.week-day:last-child {
  border-right: 0;
}

.week-heading {
  position: sticky;
  top: 0;
  z-index: 1;
  display: grid;
  gap: 2px;
  padding: 12px;
  background: #fafbfd;
  border-bottom: 1px solid #e6ebf1;
}

.week-date {
  font-size: 20px;
  font-weight: 800;
}

.week-name {
  color: var(--muted);
  font-size: 13px;
}

.week-tasks {
  display: grid;
  gap: 8px;
  padding: 10px;
}

.week-tasks .task-chip {
  min-width: 0;
}

.week-tasks .task-title {
  display: grid;
  grid-template-columns: 1fr;
  gap: 6px;
}

.week-tasks .item-actions {
  justify-self: start;
}

.task-chip,
.task-item,
.template-item {
  border: 1px solid var(--line);
  border-left-width: 4px;
  border-radius: 7px;
  background: #fff;
}

.task-chip {
  min-width: 180px;
  max-width: 100%;
  padding: 8px 10px;
}

.task-item,
.template-item {
  padding: 10px;
}

.task-chip[data-category="daily"],
.task-item[data-category="daily"],
.template-item[data-category="daily"] {
  border-left-color: var(--green);
}

.task-chip[data-category="weekly"],
.task-item[data-category="weekly"],
.template-item[data-category="weekly"] {
  border-left-color: var(--blue);
}

.task-chip[data-category="raid"],
.task-item[data-category="raid"],
.template-item[data-category="raid"] {
  border-left-color: var(--red);
}

.task-chip[data-category="craft"],
.task-item[data-category="craft"],
.template-item[data-category="craft"] {
  border-left-color: var(--amber);
}

.task-chip[data-category="event"],
.task-item[data-category="event"],
.template-item[data-category="event"] {
  border-left-color: var(--violet);
}

.task-title {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 8px;
  font-weight: 800;
}

.task-title span {
  min-width: 0;
  flex: 1;
  overflow-wrap: anywhere;
}

.task-title-toggle {
  min-width: 0;
  min-height: auto;
  flex: 1;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: inherit;
  line-height: 1.35;
  text-align: left;
  overflow-wrap: anywhere;
}

.task-title-toggle:hover {
  border: 0;
  background: transparent;
  color: var(--blue);
}

.item-actions {
  display: flex;
  flex: 0 0 auto;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: end;
}

.task-meta,
.task-note {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.task-note {
  overflow-wrap: anywhere;
}

.subtask-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #edf1f6;
}

.subtask-summary {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.subtask-controls {
  display: grid;
  gap: 6px;
}

.subtask-controls[hidden] {
  display: none;
}

.subtask-row {
  display: flex;
  align-items: start;
  gap: 7px;
  min-width: 0;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.35;
}

.subtask-row input {
  width: 15px;
  height: 15px;
  min-height: auto;
  margin: 2px 0 0;
  padding: 0;
  flex: 0 0 auto;
}

.subtask-row span {
  overflow-wrap: anywhere;
}

.subtask-row.is-done span {
  color: var(--muted);
  text-decoration: line-through;
}

.delete-button {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0 8px;
  color: var(--red);
  border-color: #f1b7b2;
  white-space: nowrap;
}

.edit-button {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0 8px;
  color: var(--blue);
  border-color: #b8c9e6;
  white-space: nowrap;
}

.side-panel {
  display: grid;
  gap: 16px;
}

.tool-panel {
  padding: 16px;
}

.panel-heading {
  margin-bottom: 14px;
}

.task-form,
.task-list,
.template-list {
  display: grid;
  gap: 10px;
}

.task-form label,
.set-controls label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  color: var(--ink);
  min-height: 38px;
  padding: 8px 10px;
}

textarea {
  resize: vertical;
}

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.weekday-picker {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  margin: 0;
  padding: 10px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
}

.weekday-picker legend {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.weekday-picker button {
  width: 100%;
  min-width: 0;
  min-height: 34px;
  padding: 0;
  border: 1px solid #e6ebf1;
  border-radius: 6px;
  background: #fafbfd;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.weekday-picker button[aria-pressed="true"] {
  border-color: var(--blue);
  background: #eaf2ff;
  color: var(--blue);
}

.weekday-picker button:hover {
  border-color: #9fb2c8;
}

.weekday-picker button[aria-pressed="true"]:hover {
  border-color: var(--blue-dark);
  background: #deebff;
}

.set-controls {
  align-items: end;
  margin-bottom: 10px;
}

.set-controls label {
  flex: 1;
}

.inline-form {
  margin-bottom: 12px;
}

.inline-form input {
  flex: 1;
}

@media (max-width: 1120px) {
  .layout {
    grid-template-columns: 1fr;
  }

  .side-panel {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 760px) {
  .app-shell {
    padding: 14px;
  }

  .planner-toolbar {
    position: relative;
    grid-template-columns: 1fr;
    grid-template-areas:
      "date"
      "range"
      "tabs";
    align-items: center;
  }

  .date-controls { grid-area: date; }
  .range-info { grid-area: range; }
  .view-tabs { grid-area: tabs; }
  #addTaskToggle {
    position: absolute;
    top: 16px;
    right: 16px;
  }

  .date-controls {
    padding-right: 132px;
  }

  .app-header,
  .home-header {
    align-items: stretch;
    grid-template-columns: minmax(0, 1fr) auto;
  }

  .clock-panel,
  .side-panel,
  .form-grid {
    display: grid;
    grid-template-columns: 1fr;
  }

  .clock-panel {
    grid-column: 1 / -1;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .settings-button {
    grid-column: 2;
  }

  .clock-panel span {
    min-height: 36px;
    padding: 0 6px;
    font-size: 12px;
    white-space: nowrap;
  }

  .settings-backdrop {
    padding: 12px;
    place-items: start stretch;
  }

  .settings-panel {
    max-height: calc(100vh - 24px);
  }

  .settings-item {
    grid-template-columns: 1fr;
  }

  .settings-actions {
    justify-content: start;
  }

  .date-controls,
  .view-tabs,
  .form-actions,
  .set-controls,
  .inline-form {
    flex-wrap: wrap;
  }

  .view-tabs button {
    flex: 1;
  }

  .hour-row {
    grid-template-columns: 54px minmax(0, 1fr);
  }

  .weekday-picker {
    grid-template-columns: repeat(7, minmax(0, 1fr));
    gap: 3px;
    padding: 8px 6px;
  }

  .weekday-picker button {
    min-height: 32px;
    font-size: 12px;
  }
}

/* ─── FF14 theme ─────────────────────────────────── */
:root[data-theme="ff14"] {
  color-scheme: dark;
  --bg: #0c0e18;
  --surface: #181b2a;
  --surface-strong: #0f1220;
  --ink: #c8d0e8;
  --muted: #7080a8;
  --line: #252a42;
  --blue: #4a78d0;
  --blue-dark: #3060b8;
  --green: #3aaa80;
  --red: #c84444;
  --amber: #c89a28;
  --violet: #8848c8;
  --shadow: 0 8px 28px rgba(0, 0, 0, 0.55);
}

:root[data-theme="ff14"] body {
  background: linear-gradient(180deg, #10162a 0, #0c0e18 320px), #0c0e18;
}

/* Gold accent */
:root[data-theme="ff14"] .section-kicker,
:root[data-theme="ff14"] .tool-link-kicker {
  color: var(--amber);
}

:root[data-theme="ff14"] .view-tab.is-active {
  background: #1c2038;
  color: var(--amber);
  box-shadow: none;
}

/* Toolbar / clock */
:root[data-theme="ff14"] .planner-toolbar {
  background: rgba(15, 18, 32, 0.98);
}

:root[data-theme="ff14"] .clock-panel span {
  background: rgba(24, 27, 42, 0.9);
}

/* Buttons */
:root[data-theme="ff14"] button:hover {
  border-color: #3d4568;
  background: #20233a;
}

:root[data-theme="ff14"] .weekday-picker button {
  background: var(--surface-strong);
  border-color: var(--line);
}

:root[data-theme="ff14"] .weekday-picker button:hover {
  border-color: #3d4568;
  background: #141728;
}

:root[data-theme="ff14"] .weekday-picker button[aria-pressed="true"] {
  background: #1a2448;
  border-color: var(--blue);
  color: #7aaae8;
}

:root[data-theme="ff14"] .weekday-picker button[aria-pressed="true"]:hover {
  background: #1e2a54;
}

:root[data-theme="ff14"] .delete-button {
  border-color: #6a2828;
}

:root[data-theme="ff14"] .edit-button {
  border-color: #2a3a6a;
}

/* Inputs */
:root[data-theme="ff14"] input,
:root[data-theme="ff14"] select,
:root[data-theme="ff14"] textarea {
  background: var(--surface-strong);
}

:root[data-theme="ff14"] input::placeholder,
:root[data-theme="ff14"] textarea::placeholder {
  color: #3a4468;
}

/* Schedule grid */
:root[data-theme="ff14"] .hour-row {
  border-bottom-color: #1c2038;
}

:root[data-theme="ff14"] .hour-label {
  background: var(--surface-strong);
  border-right-color: #1c2038;
}

:root[data-theme="ff14"] .week-heading {
  background: var(--surface-strong);
  border-bottom-color: #1c2038;
}

:root[data-theme="ff14"] .week-day {
  border-right-color: #1c2038;
}

/* Cards */
:root[data-theme="ff14"] .task-chip,
:root[data-theme="ff14"] .task-item,
:root[data-theme="ff14"] .template-item {
  background: #1c2038;
}

:root[data-theme="ff14"] .subtask-list {
  border-top-color: #252a42;
}

/* Misc surfaces */
:root[data-theme="ff14"] .settings-item {
  background: var(--surface-strong);
}

:root[data-theme="ff14"] .day-empty,
:root[data-theme="ff14"] .empty-state {
  background: var(--surface-strong);
}

:root[data-theme="ff14"] .settings-backdrop {
  background: rgba(0, 0, 8, 0.7);
}
