:root {
  color-scheme: dark;
  --bg: #171b24;
  --surface: #202630;
  --surface-soft: #2a313d;
  --text: #ffffff;
  --muted: #aab2c0;
  --line: rgba(255, 255, 255, 0.08);
  --primary: #2e7d50;
  --primary-dark: #78d5a1;
  --warning: #b96a2e;
  --danger: #ff5c66;
  --active-ring: #f5f7fb;
  --shadow: 0 12px 28px rgba(0, 0, 0, 0.28);
  --radius: 18px;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans TC", "PingFang TC", sans-serif;
  line-height: 1.5;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(100%, 720px);
  margin: 0 auto;
  padding: max(12px, env(safe-area-inset-top)) 14px max(24px, env(safe-area-inset-bottom));
}

.app-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 4px 2px 12px;
}

.date-label {
  display: block;
  margin: 0 0 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.35rem, 6vw, 1.8rem);
  line-height: 1.12;
  font-weight: 900;
}

h2 {
  font-size: 1.05rem;
  line-height: 1.3;
  font-weight: 800;
}

.sync-status {
  flex: 0 0 auto;
  max-width: 42%;
  margin-top: 4px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 800;
  line-height: 1.2;
  text-align: center;
}

.sync-status.is-ok {
  border-color: #1d6f49;
  background: #163326;
  color: #65e6a4;
}

.sync-status.is-failed {
  border-color: #7a2730;
  background: #35171b;
  color: #ff8b94;
}

main {
  display: grid;
  gap: 10px;
}

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

.card {
  padding: 13px 14px;
}

.active-card {
  position: relative;
  overflow: hidden;
  min-height: 64px;
  border-color: var(--line);
  background: var(--surface);
}

.active-card.is-running {
  min-height: 94px;
  padding-bottom: 12px;
  background: #202630;
  color: #ffffff;
}

.active-card__top,
.section-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

.active-card h2 {
  max-width: calc(100% - 52px);
  font-size: clamp(1.05rem, 5vw, 1.55rem);
  font-weight: 900;
}

.timer-details {
  margin: 5px 0 0;
  color: currentColor;
  font-size: 0.95rem;
  font-weight: 800;
}

.timer-details > strong {
  display: block;
  font-size: clamp(1.65rem, 8vw, 2.4rem);
  line-height: 1;
  font-variant-numeric: tabular-nums;
  font-weight: 950;
}

.timer-details span {
  display: block;
  margin-top: 4px;
  color: var(--muted);
}

.timer-details span strong {
  color: #ffffff;
  font-variant-numeric: tabular-nums;
  font-weight: 950;
}

.elapsed-time {
  font-variant-numeric: tabular-nums;
}

.stop-timer-button {
  position: absolute;
  right: 16px;
  top: 12px;
  min-height: 0;
  margin: 0;
  padding: 3px 0;
  border: 0;
  background: transparent;
  color: #cfd6e2;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 950;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.category-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: minmax(112px, 1fr);
  gap: 14px;
  min-height: min(58vh, 580px);
}

.category-button,
.secondary-button,
.primary-button,
.text-button {
  border: 0;
  cursor: pointer;
}

.category-button {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 112px;
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  color: #ffffff;
  text-align: center;
  padding: 18px;
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.14),
    0 8px 18px rgba(0, 0, 0, 0.18);
}

.category-button.is-active {
  border-color: rgba(255, 255, 255, 0.72);
  box-shadow:
    0 0 0 3px rgba(255, 255, 255, 0.64),
    0 0 18px rgba(255, 255, 255, 0.18),
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 12px 26px rgba(0, 0, 0, 0.3);
  transform: translateY(-2px);
}

.category-memoriq {
  background: #4F4370;
  color: #FFFFFF;
}

.category-memoriq.is-active {
  background: #6B56A0;
}

.category-course {
  background: #286B47;
  color: #FFFFFF;
}

.category-course.is-active {
  background: #368D5C;
}

.category-strategy {
  background: #9B5A2C;
  color: #FFFFFF;
}

.category-strategy.is-active {
  background: #CC7837;
}

.category-admin {
  background: #354F73;
  color: #FFFFFF;
}

.category-admin.is-active {
  background: #476EA3;
}

.category-field {
  background: #E8CA54;
  color: #FFFFFF;
  min-height: 122px;
}

.category-field.is-active {
  background: #E8CA54;
}

.category-name {
  display: block;
  width: 100%;
  font-size: clamp(1.4rem, 4.4vw, 2.35rem);
  font-weight: 820;
  line-height: 1.15;
  text-align: center;
}

.category-field {
  grid-column: 1 / -1;
}

.today-summary-card {
  cursor: pointer;
  list-style: none;
  box-shadow: none;
}

.today-summary-card::-webkit-details-marker {
  display: none;
}

.allocation-bar {
  display: flex;
  width: 100%;
  height: 14px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 999px;
  background: var(--surface-soft);
}

.allocation-segment,
.allocation-empty {
  display: block;
  min-width: 4px;
  flex-basis: 0;
}

.allocation-empty {
  width: 100%;
  background: var(--surface-soft);
}

.totals-list,
.weekly-progress,
.end-day-totals {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.total-row,
.progress-row {
  display: grid;
  gap: 4px;
  padding: 7px 0;
  border-bottom: 1px solid var(--line);
}

.total-row:last-child,
.progress-row:last-child {
  border-bottom: 0;
}

.total-row__main,
.progress-row__main {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-weight: 800;
}

.total-row__main strong,
.progress-row__main strong,
#todayTotalHours,
#weekRangeLabel {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  font-size: 0.94rem;
  font-weight: 950;
}

.progress-bar-text {
  color: var(--muted);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0;
  white-space: nowrap;
}

.progress-row.has-target {
  margin-inline: -5px;
  padding-inline: 5px;
  border-radius: var(--radius);
  background: transparent;
}

.progress-row.has-target .progress-row__main span {
  color: var(--text);
}

.progress-row.has-target .progress-row__main strong {
  color: var(--text);
}

.progress-row.no-target {
  color: var(--muted);
}

.progress-row.no-target .progress-row__main {
  font-weight: 700;
}

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

.detail-panel {
  display: grid;
  gap: 8px;
}

.detail-panel > summary {
  cursor: pointer;
  list-style: none;
  padding: 0;
  color: var(--muted);
  font-weight: 900;
  text-align: initial;
}

.detail-panel > summary::-webkit-details-marker {
  display: none;
}

.detail-panel[open] > summary {
  color: var(--text);
}

.detail-panel[open] > .card,
.detail-panel[open] > .action-row {
  margin-top: 8px;
}

.secondary-button,
.primary-button {
  min-height: 50px;
  border-radius: var(--radius);
  font-weight: 850;
}

.secondary-button {
  border: 1px solid var(--line);
  background: var(--surface-soft);
  color: var(--text);
  box-shadow: none;
}

.primary-button {
  width: 100%;
  margin-top: 14px;
  background: var(--primary);
  color: #ffffff;
}

.text-button {
  flex: 0 0 auto;
  padding: 4px 0;
  background: transparent;
  color: var(--primary-dark);
  font-size: 0.9rem;
  font-weight: 800;
}

.report-output,
.reflection-input,
.settings-input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #111318;
  color: var(--text);
}

.report-output {
  min-height: 420px;
  margin-top: 14px;
  padding: 12px;
  resize: vertical;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  white-space: pre;
}

.settings-form {
  display: grid;
  gap: 12px;
  margin-top: 14px;
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr minmax(88px, 120px);
  align-items: center;
  gap: 12px;
}

.settings-row label {
  font-weight: 800;
}

.settings-input {
  min-height: 46px;
  padding: 8px 10px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: end center;
  padding: 16px;
  background: #050609;
}

.dialog {
  width: min(100%, 560px);
  max-height: min(86vh, 720px);
  overflow: auto;
  padding: 18px;
}

.reflection-label {
  display: block;
  margin-top: 18px;
  font-size: 1.05rem;
  font-weight: 850;
}

.reflection-input {
  min-height: 112px;
  margin-top: 8px;
  padding: 12px;
  resize: vertical;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: max(16px, env(safe-area-inset-bottom));
  left: 16px;
  z-index: 30;
  width: min(calc(100% - 32px), 520px);
  margin: 0 auto;
  padding: 12px 14px;
  border-radius: var(--radius);
  background: #252b35;
  color: #ffffff;
  font-weight: 750;
  text-align: center;
  box-shadow: var(--shadow);
}

[hidden] {
  display: none !important;
}

@media (min-width: 560px) {
  .category-grid {
    grid-template-columns: repeat(2, 1fr);
    grid-auto-rows: minmax(110px, 1fr);
    min-height: min(54vh, 500px);
  }

  .category-button {
    min-height: 110px;
  }

  .category-field {
    grid-column: span 2;
    min-height: 118px;
  }

  .action-row {
    grid-template-columns: repeat(3, 1fr);
  }

  .overlay {
    place-items: center;
  }
}
