:root {
  color-scheme: light;
  --bg: #eef4f2;
  --surface: #ffffff;
  --surface-muted: #f6f8f7;
  --ink: #17211f;
  --muted: #61706b;
  --line: #d7e0dd;
  --teal: #0f766e;
  --teal-dark: #0b4f4a;
  --coral: #d95f42;
  --gold: #b7791f;
  --plum: #8b4a70;
  --blue: #2563eb;
  --danger: #b42318;
  --shadow: 0 16px 34px rgba(15, 35, 30, 0.09);
  --swatch-teal: #0f766e;
  --swatch-ocean: #2563eb;
  --swatch-forest: #2f6f3e;
  --swatch-plum: #8b4a70;
  --swatch-graphite: #334155;
}

body[data-theme="ocean"] {
  --bg: #eef5fb;
  --surface-muted: #f3f7fb;
  --line: #d4e0ea;
  --teal: #2563eb;
  --teal-dark: #1d4ed8;
  --coral: #d95f42;
  --shadow: 0 16px 34px rgba(30, 58, 138, 0.1);
}

body[data-theme="forest"] {
  --bg: #eff5ed;
  --surface-muted: #f5f8f3;
  --line: #d7e3d2;
  --teal: #2f6f3e;
  --teal-dark: #245533;
  --coral: #c65f35;
  --shadow: 0 16px 34px rgba(36, 85, 51, 0.1);
}

body[data-theme="plum"] {
  --bg: #f4eff4;
  --surface-muted: #f8f4f8;
  --line: #e1d4df;
  --teal: #8b4a70;
  --teal-dark: #693853;
  --coral: #cf6542;
  --shadow: 0 16px 34px rgba(86, 44, 69, 0.1);
}

body[data-theme="graphite"] {
  --bg: #eef1f4;
  --surface-muted: #f5f6f8;
  --line: #d7dde4;
  --teal: #334155;
  --teal-dark: #1f2937;
  --coral: #0f766e;
  --shadow: 0 16px 34px rgba(31, 41, 55, 0.1);
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100%;
  margin: 0;
  background:
    linear-gradient(180deg, rgba(15, 118, 110, 0.08), rgba(238, 244, 242, 0) 280px),
    var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
}

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

button {
  cursor: pointer;
}

svg {
  width: 20px;
  height: 20px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.icon-sprite {
  display: none;
}

.app-shell {
  width: min(1440px, calc(100% - 28px));
  margin: 0 auto;
  padding: 18px 0 36px;
}

.topbar,
.datebar,
.panel {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
  box-shadow: var(--shadow);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 78px;
  padding: 14px;
  border-radius: 8px;
}

.brand,
.top-actions,
.datebar,
.panel-heading,
.calendar-actions,
.timer-controls,
.backup-actions {
  display: flex;
  align-items: center;
}

.brand {
  gap: 12px;
  min-width: 0;
}

.brand-mark {
  display: grid;
  flex: 0 0 46px;
  width: 46px;
  height: 46px;
  place-items: center;
  border-radius: 8px;
  background: var(--teal);
  color: #fff;
}

.brand h1 {
  margin: 0;
  font-size: 1.45rem;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p,
.panel-heading p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.93rem;
}

.top-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.theme-switcher {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-height: 42px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.theme-swatch {
  display: grid;
  width: 32px;
  min-height: 32px;
  place-items: center;
  border: 1px solid transparent;
  border-radius: 7px;
  background: transparent;
  padding: 0;
}

.theme-swatch span {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px rgba(23, 33, 31, 0.16);
}

.theme-swatch.active {
  border-color: var(--teal);
  background: var(--surface-muted);
}

.theme-teal span {
  background: var(--swatch-teal);
}

.theme-ocean span {
  background: var(--swatch-ocean);
}

.theme-forest span {
  background: var(--swatch-forest);
}

.theme-plum span {
  background: var(--swatch-plum);
}

.theme-graphite span {
  background: var(--swatch-graphite);
}

.button,
.icon-button {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  transition: background 160ms ease, border-color 160ms ease, color 160ms ease, transform 160ms ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 0 13px;
  white-space: nowrap;
}

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

.button.secondary {
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.button:hover,
.icon-button:hover {
  transform: translateY(-1px);
}

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

.button.secondary:hover,
.icon-button:hover {
  border-color: #a6b7b2;
  background: var(--surface-muted);
}

.icon-button {
  display: inline-grid;
  width: 42px;
  flex: 0 0 42px;
  place-items: center;
  border-color: var(--line);
  background: #fff;
  color: var(--ink);
}

.button svg,
.icon-button svg {
  pointer-events: none;
}

.icon-button.small {
  width: 36px;
  min-height: 36px;
  flex-basis: 36px;
}

.icon-button.strong {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.datebar {
  gap: 10px;
  margin-top: 14px;
  padding: 10px;
  border-radius: 8px;
}

.datebar-main {
  display: grid;
  grid-template-columns: auto minmax(160px, 1fr);
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.mobile-section-nav {
  display: none;
}

.datebar-main label,
.entry-form span,
.timer-settings span {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0;
}

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

input,
select {
  min-height: 42px;
  padding: 0 11px;
}

textarea {
  resize: vertical;
  min-height: 230px;
  padding: 12px;
  line-height: 1.5;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
  outline: 3px solid rgba(15, 118, 110, 0.22);
  outline-offset: 2px;
}

.dashboard {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 12px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 14px;
  border-radius: 8px;
  scroll-margin-top: 82px;
}

.calendar-panel {
  grid-column: 1 / -1;
}

.panel-heading {
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.panel-heading h2 {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
  letter-spacing: 0;
}

.panel-icon {
  flex: 0 0 auto;
  color: var(--teal);
}

.entry-form {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.entry-form label,
.timer-settings label {
  display: grid;
  gap: 5px;
  min-width: 0;
}

.entry-form .wide-input {
  grid-column: 1 / -1;
}

.entry-form .full-row {
  grid-column: 1 / -1;
}

.compact-form {
  grid-template-columns: minmax(160px, 1fr) 110px;
}

.schedule-form label:nth-child(4),
.schedule-form label:nth-child(5),
.todo-form label:nth-child(4) {
  grid-column: 1 / -1;
}

.schedule-form label:nth-child(1) {
  grid-column: 1;
  grid-row: 1;
}

.schedule-form label:nth-child(3) {
  grid-column: 2;
  grid-row: 1;
}

.schedule-form .wide-input {
  grid-row: 2;
}

.item-list,
.habit-list {
  display: grid;
  gap: 8px;
}

.item-list.empty,
.habit-list.empty {
  min-height: 74px;
  place-items: center;
  border: 1px dashed #b8c7c3;
  border-radius: 8px;
  color: var(--muted);
  text-align: center;
  padding: 16px;
}

.planner-item,
.habit-item {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: 10px;
  align-items: start;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
}

.planner-item.done {
  background: #f7faf9;
  color: #6a7773;
}

.planner-item.done .item-title {
  text-decoration: line-through;
}

.item-time,
.item-check,
.habit-check {
  display: grid;
  width: 38px;
  min-height: 38px;
  place-items: center;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--surface-muted);
  color: var(--teal);
  font-size: 0.82rem;
  font-weight: 800;
}

.item-check,
.habit-check {
  background: #fff;
}

.item-check.checked,
.habit-check.checked {
  border-color: var(--teal);
  background: var(--teal);
  color: #fff;
}

.item-main {
  min-width: 0;
}

.item-title {
  margin: 0;
  overflow-wrap: anywhere;
  font-weight: 750;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.priority-pill,
.habit-streak {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 800;
}

.priority-high {
  background: #fde8e4;
  color: var(--danger);
}

.priority-medium {
  background: #fff3d7;
  color: var(--gold);
}

.priority-low {
  background: #e4f4f2;
  color: var(--teal-dark);
}

.item-actions {
  display: flex;
  gap: 6px;
}

.item-actions button {
  min-height: 34px;
  width: 34px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--muted);
}

.item-actions button:hover {
  color: var(--danger);
}

.segmented {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 4px;
  margin: 10px 0 12px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-muted);
}

.segmented button {
  min-height: 34px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-weight: 800;
}

.segmented button.active {
  background: #fff;
  color: var(--teal);
  box-shadow: 0 1px 4px rgba(15, 35, 30, 0.08);
}

.timer-face {
  position: relative;
  display: grid;
  min-height: 178px;
  place-items: center;
  margin: 8px 0 12px;
}

#timerDisplay {
  z-index: 1;
  font-size: 3.35rem;
  font-weight: 850;
  letter-spacing: 0;
}

.timer-ring {
  position: absolute;
  width: 168px;
  height: 168px;
  border: 10px solid #d8ebe8;
  border-top-color: var(--coral);
  border-right-color: var(--teal);
  border-radius: 50%;
}

.timer-controls {
  justify-content: center;
  gap: 10px;
  margin-bottom: 14px;
}

.timer-settings {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.habit-item {
  grid-template-columns: auto minmax(0, 1fr) auto;
}

.habit-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  margin: 0;
  font-weight: 750;
}

.habit-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
  background: var(--teal);
}

.habit-dot.coral {
  background: var(--coral);
}

.habit-dot.gold {
  background: var(--gold);
}

.habit-dot.plum {
  background: var(--plum);
}

.habit-title span:last-child {
  overflow-wrap: anywhere;
}

.habit-streak {
  margin-top: 6px;
  background: #edf2f7;
  color: #34423f;
}

.calendar-actions {
  gap: 6px;
}

.calendar-weekdays,
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 6px;
}

.calendar-weekdays {
  margin-bottom: 6px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 800;
  text-align: center;
  text-transform: uppercase;
  letter-spacing: 0;
}

.calendar-day {
  display: grid;
  min-height: 72px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
  text-align: left;
  align-content: space-between;
}

.calendar-day.outside {
  opacity: 0.45;
}

.calendar-day.today {
  border-color: var(--coral);
}

.calendar-day.selected {
  border-color: var(--teal);
  background: #e8f4f2;
}

.calendar-date {
  font-weight: 850;
}

.calendar-counts {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  min-height: 18px;
}

.calendar-counts span {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 1px 5px;
  border-radius: 999px;
  background: var(--surface-muted);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
}

.backup-actions {
  gap: 8px;
  flex-wrap: wrap;
}

.backup-meta {
  display: grid;
  gap: 8px;
  margin: 12px 0 0;
}

.backup-meta div {
  display: grid;
  grid-template-columns: 96px minmax(0, 1fr);
  gap: 10px;
  padding: 8px 0;
  border-top: 1px solid var(--line);
}

.backup-meta dt {
  color: var(--muted);
  font-weight: 800;
}

.backup-meta dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 20;
  max-width: min(420px, calc(100% - 32px));
  padding: 12px 14px;
  border-radius: 8px;
  background: #17211f;
  color: #fff;
  box-shadow: var(--shadow);
  opacity: 0;
  pointer-events: none;
  transform: translateY(10px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 1500px) {
  .dashboard {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(320px, 0.75fr);
  }

  .calendar-panel {
    grid-column: span 2;
  }
}

@media (max-width: 1180px) {
  .calendar-panel {
    grid-column: 1 / -1;
  }
}

@media (max-width: 820px) {
  .app-shell {
    width: min(100% - 18px, 720px);
    padding-top: 9px;
  }

  .topbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .top-actions {
    width: 100%;
    justify-content: stretch;
  }

  .theme-switcher {
    flex: 1 1 100%;
    justify-content: space-between;
  }

  .theme-swatch {
    width: 100%;
  }

  .top-actions .button {
    flex: 1;
  }

  .datebar {
    flex-wrap: wrap;
  }

  .mobile-section-nav {
    position: sticky;
    top: 0;
    z-index: 12;
    display: flex;
    gap: 6px;
    margin-top: 8px;
    padding: 6px;
    overflow-x: auto;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 10px 24px rgba(15, 35, 30, 0.09);
    scrollbar-width: thin;
  }

  .mobile-section-nav a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-width: 88px;
    min-height: 40px;
    padding: 0 10px;
    border: 1px solid var(--line);
    border-radius: 8px;
    background: #fff;
    color: var(--ink);
    font-size: 0.88rem;
    font-weight: 800;
    text-decoration: none;
    touch-action: manipulation;
  }

  .mobile-section-nav svg {
    width: 17px;
    height: 17px;
    color: var(--teal);
  }

  .datebar-main {
    grid-template-columns: 1fr;
    order: -1;
    flex-basis: 100%;
  }

  .dashboard {
    grid-template-columns: 1fr;
  }

  .calendar-panel {
    grid-column: auto;
    order: 1;
  }

  .schedule-panel {
    order: 2;
  }

  .todo-panel {
    order: 3;
  }

  .pomodoro-panel {
    order: 4;
  }

  .habits-panel {
    order: 5;
  }

  .notes-panel {
    order: 6;
  }

  .backup-panel {
    order: 7;
  }

  .entry-form,
  .compact-form {
    grid-template-columns: 1fr;
  }

  .schedule-form label:nth-child(4),
  .schedule-form label:nth-child(5),
  .todo-form label:nth-child(4) {
    grid-column: auto;
  }

  .schedule-form label:nth-child(1),
  .schedule-form label:nth-child(3),
  .schedule-form .wide-input {
    grid-column: auto;
    grid-row: auto;
  }
}

@media (max-width: 520px) {
  body {
    font-size: 15px;
  }

  .brand h1 {
    font-size: 1.18rem;
  }

  .top-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .button {
    width: 100%;
  }

  .planner-item,
  .habit-item {
    grid-template-columns: auto minmax(0, 1fr);
  }

  .item-actions {
    grid-column: 1 / -1;
    justify-content: flex-end;
  }

  .calendar-weekdays,
  .calendar-grid {
    gap: 4px;
  }

  .calendar-day {
    min-height: 52px;
    padding: 5px;
    border-radius: 7px;
  }

  .calendar-weekdays {
    gap: 4px;
    font-size: 0.68rem;
  }

  .calendar-date {
    font-size: 0.92rem;
  }

  .calendar-counts span {
    min-height: 16px;
    padding: 0 3px;
    font-size: 0.62rem;
  }

  #timerDisplay {
    font-size: 2.8rem;
  }
}
