:root {
  color-scheme: dark;
  --color-background: #050813;
  --color-surface: #0c1322;
  --color-surface-raised: #111b2f;
  --color-text: #f3f7ff;
  --color-muted: #9ba9be;
  --color-border: #263652;
  --color-primary: #e62f3c;
  --color-primary-hover: #ff4050;
  --color-secondary: #111a2b;
  --color-secondary-hover: #18253b;
  --color-danger: #ff6671;
  --color-danger-background: rgba(230, 47, 60, 0.1);
  --color-blue-accent: #2774c7;
  --color-cold-white: #f7faff;
  --shadow-soft: 0 20px 56px rgba(0, 0, 0, 0.32);
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  padding-right: env(safe-area-inset-right);
  padding-left: env(safe-area-inset-left);
  color: var(--color-text);
  background:
    radial-gradient(circle at 82% 12%, rgba(30, 81, 143, 0.2), transparent 30%),
    radial-gradient(circle at 12% 88%, rgba(170, 22, 38, 0.12), transparent 32%),
    linear-gradient(160deg, #080d1b 0%, var(--color-background) 52%, #03050c 100%);
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

body::before,
body::after {
  position: fixed;
  z-index: 0;
  inset: 0;
  content: "";
  pointer-events: none;
}

body::before {
  background:
    repeating-radial-gradient(
      circle at 6% 8%,
      transparent 0 35px,
      rgba(232, 55, 67, 0.12) 36px 37px,
      transparent 38px 71px
    ),
    repeating-conic-gradient(
      from 7deg at 6% 8%,
      transparent 0 14deg,
      rgba(123, 159, 205, 0.11) 14.5deg 15deg,
      transparent 15.5deg 30deg
    );
  -webkit-mask-image: radial-gradient(
    circle at 6% 8%,
    #000 0,
    rgba(0, 0, 0, 0.82) 34%,
    transparent 74%
  );
  mask-image: radial-gradient(
    circle at 6% 8%,
    #000 0,
    rgba(0, 0, 0, 0.82) 34%,
    transparent 74%
  );
}

body::after {
  background:
    repeating-radial-gradient(
      circle at 97% 92%,
      transparent 0 42px,
      rgba(39, 116, 199, 0.09) 43px 44px,
      transparent 45px 83px
    ),
    repeating-conic-gradient(
      from -8deg at 97% 92%,
      transparent 0 17deg,
      rgba(232, 55, 67, 0.085) 17.4deg 18deg,
      transparent 18.6deg 36deg
    );
  -webkit-mask-image: radial-gradient(
    circle at 97% 92%,
    #000 0,
    rgba(0, 0, 0, 0.78) 30%,
    transparent 58%
  );
  mask-image: radial-gradient(
    circle at 97% 92%,
    #000 0,
    rgba(0, 0, 0, 0.78) 30%,
    transparent 58%
  );
}

::selection {
  color: #ffffff;
  background: rgba(230, 47, 60, 0.72);
}

button,
select {
  font: inherit;
  touch-action: manipulation;
}

.app-shell {
  position: relative;
  z-index: 1;
  width: min(920px, calc(100% - 48px));
  margin: 0 auto;
  padding:
    max(48px, calc(env(safe-area-inset-top) + 24px))
    0
    max(64px, calc(env(safe-area-inset-bottom) + 32px));
}

.page-header {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 32px;
  margin-bottom: 28px;
}

.eyebrow,
.section-label {
  margin: 0 0 6px;
  color: var(--color-primary);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.12em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.75rem, 4vw, 2.25rem);
  line-height: 1.2;
  letter-spacing: -0.03em;
  color: var(--color-cold-white);
  text-shadow:
    -1px 0 rgba(230, 47, 60, 0.72),
    1px 1px rgba(39, 116, 199, 0.6);
}

.current-date {
  padding-bottom: 4px;
  color: var(--color-muted);
  font-size: 0.95rem;
  white-space: nowrap;
}

.timer-panel,
.today-panel,
.statistics-panel,
.history-panel {
  position: relative;
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 14px;
  background:
    linear-gradient(145deg, rgba(16, 26, 45, 0.97), rgba(8, 14, 26, 0.98));
  box-shadow: var(--shadow-soft);
}

.timer-panel {
  border-top-color: rgba(230, 47, 60, 0.82);
  background:
    linear-gradient(
        90deg,
        var(--color-primary) 0 58%,
        var(--color-blue-accent) 58% 76%,
        transparent 76%
      )
      top / 100% 3px no-repeat,
    linear-gradient(145deg, rgba(16, 26, 45, 0.97), rgba(8, 14, 26, 0.98));
  box-shadow:
    inset 3px 0 0 rgba(230, 47, 60, 0.72),
    inset -1px 0 0 rgba(39, 116, 199, 0.35),
    var(--shadow-soft);
}

.timer-panel::before,
.timer-panel::after {
  position: absolute;
  z-index: 0;
  top: 22px;
  width: 34px;
  height: 46px;
  content: "";
  opacity: 0.7;
  background: radial-gradient(
    ellipse at 50% 52%,
    rgba(8, 14, 26, 0.98) 0 43%,
    rgba(247, 250, 255, 0.98) 48% 100%
  );
  filter:
    drop-shadow(-1px 0 0 rgba(230, 47, 60, 0.46))
    drop-shadow(1px 1px 0 rgba(39, 116, 199, 0.48));
  pointer-events: none;
}

.timer-panel::before {
  right: 72px;
  clip-path: polygon(8% 4%, 96% 20%, 72% 100%, 10% 72%);
  transform: rotate(-8deg) skewY(-4deg);
}

.timer-panel::after {
  right: 28px;
  clip-path: polygon(4% 20%, 92% 4%, 90% 72%, 28% 100%);
  transform: rotate(8deg) skewY(4deg);
}

.timer-panel > * {
  position: relative;
  z-index: 1;
}

.today-panel,
.statistics-panel,
.history-panel {
  box-shadow:
    inset 3px 0 0 rgba(39, 116, 199, 0.52),
    var(--shadow-soft);
}

.timer-panel {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 40px 48px 44px;
}

.subject-field {
  display: flex;
  align-items: center;
  gap: 12px;
  align-self: flex-start;
}

.subject-field label {
  color: var(--color-muted);
  font-size: 0.9rem;
}

.subject-field select {
  min-width: 132px;
  min-height: 44px;
  padding: 9px 36px 9px 12px;
  border: 1px solid var(--color-border);
  border-radius: 9px;
  color: var(--color-text);
  background: rgba(7, 13, 25, 0.9);
  cursor: pointer;
}

.subject-field select:focus-visible,
.button:focus-visible {
  outline: 3px solid rgba(255, 65, 80, 0.32);
  outline-offset: 2px;
}

.timer-display {
  max-width: 100%;
  margin-top: 42px;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: clamp(3.5rem, 10vw, 6.5rem);
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  line-height: 1;
  letter-spacing: -0.07em;
  color: var(--color-cold-white);
  text-shadow:
    -2px 0 rgba(230, 47, 60, 0.35),
    2px 1px rgba(39, 116, 199, 0.42),
    0 0 28px rgba(182, 210, 255, 0.12);
  white-space: nowrap;
}

.timer-hint {
  margin: 18px 0 32px;
  color: var(--color-muted);
  font-size: 0.9rem;
}

.timer-actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(112px, 1fr));
  gap: 12px;
  width: min(100%, 424px);
}

.button {
  min-height: 48px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: 7px;
  font-weight: 600;
  cursor: pointer;
  transition:
    background-color 120ms ease,
    border-color 120ms ease,
    transform 120ms ease;
}

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

.button:active {
  transform: translateY(0);
}

.button:disabled,
.button:disabled:hover {
  border-color: var(--color-border);
  color: #68768c;
  background: #0d1421;
  cursor: not-allowed;
  opacity: 0.72;
  transform: none;
}

.button-primary {
  color: #ffffff;
  background: linear-gradient(145deg, #ef3544, #b91629);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.2),
    0 8px 20px rgba(187, 20, 39, 0.22);
}

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

.button-secondary {
  border-color: #3a4d6d;
  color: var(--color-text);
  background: rgba(8, 14, 27, 0.84);
}

.button-secondary:hover {
  background: var(--color-secondary-hover);
}

.button-danger {
  border-color: rgba(230, 47, 60, 0.58);
  color: var(--color-danger);
  background: var(--color-danger-background);
}

.button-danger:hover {
  border-color: var(--color-primary-hover);
  background: rgba(230, 47, 60, 0.17);
}

.today-panel,
.statistics-panel,
.history-panel {
  margin-top: 20px;
  padding: 28px 32px 32px;
}

.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding-bottom: 22px;
  border-bottom: 1px solid var(--color-border);
}

.section-header h2 {
  margin-bottom: 0;
  font-size: 1.25rem;
}

.today-total {
  text-align: right;
}

.today-total span {
  display: block;
  margin-bottom: 3px;
  color: var(--color-muted);
  font-size: 0.8rem;
}

.today-total strong {
  color: var(--color-primary);
  font-size: 1.05rem;
}

.statistics-overview {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 20px;
}

.statistics-metric {
  min-width: 0;
  padding: 17px 18px;
  border: 1px solid rgba(54, 76, 108, 0.68);
  border-radius: 10px;
  background: rgba(7, 13, 25, 0.72);
}

.statistics-metric span {
  display: block;
  margin-bottom: 5px;
  color: var(--color-muted);
  font-size: 0.78rem;
}

.statistics-metric strong {
  color: var(--color-cold-white);
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
}

.statistics-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr);
  gap: 16px;
  margin-top: 16px;
}

.statistics-card {
  min-width: 0;
  padding: 18px;
  border: 1px solid var(--color-border);
  border-radius: 11px;
  background: rgba(7, 13, 25, 0.66);
}

.statistics-card-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
}

.statistics-card-header h3 {
  margin: 0;
  font-size: 0.95rem;
}

.statistics-card-header > span {
  color: var(--color-muted);
  font-size: 0.72rem;
  white-space: nowrap;
}

.weekly-chart {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  align-items: end;
  gap: 7px;
  width: 100%;
  min-width: 0;
}

.weekly-chart-column {
  display: grid;
  min-width: 0;
  grid-template-rows: 25px 132px auto;
  align-items: end;
  justify-items: center;
}

.weekly-chart-value {
  max-width: 100%;
  overflow: hidden;
  color: var(--color-muted);
  font-size: 0.64rem;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.weekly-chart-track {
  position: relative;
  display: flex;
  width: min(72%, 32px);
  height: 124px;
  align-items: flex-end;
  overflow: hidden;
  border: 1px solid rgba(54, 76, 108, 0.45);
  border-radius: 6px 6px 3px 3px;
  background:
    repeating-linear-gradient(
      to top,
      transparent 0 30px,
      rgba(83, 112, 151, 0.12) 30px 31px
    ),
    rgba(11, 19, 34, 0.82);
}

.weekly-chart-bar {
  display: block;
  width: 100%;
  min-height: 0;
  border-radius: 5px 5px 2px 2px;
  background: linear-gradient(to top, #a8172a, var(--color-primary));
  box-shadow: 0 0 14px rgba(230, 47, 60, 0.2);
}

.weekly-chart-date {
  display: grid;
  gap: 1px;
  margin-top: 7px;
  color: var(--color-text);
  font-size: 0.66rem;
  font-variant-numeric: tabular-nums;
  line-height: 1.25;
  text-align: center;
  white-space: nowrap;
}

.weekly-chart-date span:last-child {
  color: var(--color-muted);
  font-size: 0.62rem;
}

.subject-statistics {
  display: grid;
  gap: 17px;
}

.subject-statistic-row {
  min-width: 0;
}

.subject-statistic-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 7px;
}

.subject-statistic-heading strong {
  font-size: 0.86rem;
}

.subject-statistic-heading span {
  min-width: 0;
  overflow: hidden;
  color: var(--color-muted);
  font-size: 0.72rem;
  font-variant-numeric: tabular-nums;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.subject-statistic-track {
  height: 8px;
  overflow: hidden;
  border-radius: 999px;
  background: #111c30;
}

.subject-statistic-fill {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: var(--color-primary);
}

.subject-statistic-row[data-subject="english"] .subject-statistic-fill {
  background: #3d8bd7;
}

.subject-statistic-row[data-subject="politics"] .subject-statistic-fill {
  background: #d7a83d;
}

.subject-statistic-row[data-subject="major"] .subject-statistic-fill {
  background: #9b6bd3;
}

.empty-state {
  display: flex;
  min-height: 150px;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--color-muted);
  text-align: center;
}

.empty-state-icon {
  margin-bottom: 8px;
  color: #617493;
  font-size: 1.5rem;
  line-height: 1;
}

.empty-state p {
  margin-bottom: 4px;
  color: var(--color-text);
  font-size: 0.95rem;
  font-weight: 600;
}

.empty-state > span:last-child {
  font-size: 0.82rem;
}

.study-record-list {
  padding: 0;
  margin: 0;
  list-style: none;
}

.study-record {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 19px 4px;
  border-bottom: 1px solid var(--color-border);
  overflow-wrap: anywhere;
}

.study-record:last-child {
  padding-bottom: 3px;
  border-bottom: 0;
}

.record-main {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 4px;
}

.record-subject {
  font-weight: 650;
}

.record-time-range {
  color: var(--color-muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

.record-duration {
  color: var(--color-primary);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.record-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.record-delete-button {
  padding: 5px 8px;
  border: 1px solid transparent;
  border-radius: 7px;
  color: var(--color-danger);
  background: transparent;
  font-size: 0.8rem;
  cursor: pointer;
}

.record-delete-button:hover {
  border-color: rgba(230, 47, 60, 0.5);
  background: var(--color-danger-background);
}

.record-delete-button:focus-visible {
  outline: 3px solid rgba(255, 65, 80, 0.28);
  outline-offset: 2px;
}

.history-day-list {
  display: grid;
  gap: 12px;
  margin-top: 20px;
}

.history-day {
  overflow: hidden;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: rgba(7, 13, 25, 0.78);
}

.history-day[open] {
  border-color: #344866;
  background: rgba(14, 23, 40, 0.95);
}

.history-day-summary {
  min-height: 44px;
  padding: 17px 18px;
  cursor: pointer;
}

.history-day-summary::marker {
  color: var(--color-primary);
}

.history-day-summary:focus-visible {
  outline: 3px solid rgba(255, 65, 80, 0.28);
  outline-offset: -3px;
}

.history-day-heading {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 11px;
}

.history-day-date {
  font-weight: 700;
}

.history-day-total {
  color: var(--color-primary);
  font-size: 0.88rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.subject-total-list {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
  padding: 0;
  margin: 0;
  list-style: none;
}

.subject-total-item {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 5px 9px;
  border-radius: 7px;
  color: var(--color-muted);
  border: 1px solid rgba(54, 76, 108, 0.55);
  background: rgba(17, 26, 43, 0.9);
  font-size: 0.78rem;
}

.subject-total-item strong {
  color: var(--color-text);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
}

.history-record-list {
  padding: 0 18px 14px;
  border-top: 1px solid var(--color-border);
}

.background-confirmation[hidden] {
  display: none;
}

.background-confirmation {
  position: fixed;
  z-index: 10;
  inset: 0;
  display: grid;
  place-items: center;
  padding:
    max(20px, env(safe-area-inset-top))
    max(20px, env(safe-area-inset-right))
    max(20px, env(safe-area-inset-bottom))
    max(20px, env(safe-area-inset-left));
  background: rgba(2, 5, 12, 0.78);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}

.background-confirmation-card {
  width: min(100%, 420px);
  padding: 28px;
  border: 1px solid var(--color-border);
  border-radius: 12px;
  background: linear-gradient(145deg, #111b2f, #090f1d);
  box-shadow:
    inset 3px 0 0 var(--color-primary),
    0 24px 64px rgba(0, 0, 0, 0.52);
}

.background-confirmation-card h2 {
  margin-bottom: 12px;
  font-size: 1.25rem;
}

.background-confirmation-message {
  margin-bottom: 24px;
  color: var(--color-muted);
}

.background-confirmation-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 640px) {
  .app-shell {
    width: min(100% - 28px, 920px);
    padding:
      max(28px, calc(env(safe-area-inset-top) + 16px))
      0
      max(40px, calc(env(safe-area-inset-bottom) + 24px));
  }

  .page-header,
  .section-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 12px;
  }

  .timer-panel {
    padding: 28px 20px 32px;
  }

  .timer-panel::before,
  .timer-panel::after {
    top: 18px;
    width: 22px;
    height: 30px;
    opacity: 0.46;
    filter:
      drop-shadow(-1px 0 0 rgba(230, 47, 60, 0.34))
      drop-shadow(1px 0 0 rgba(39, 116, 199, 0.36));
  }

  .timer-panel::before {
    right: 47px;
  }

  .timer-panel::after {
    right: 18px;
  }

  .timer-display {
    margin-top: 36px;
    font-size: clamp(2.75rem, 16vw, 4.5rem);
    letter-spacing: -0.08em;
  }

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

  .today-panel,
  .statistics-panel,
  .history-panel {
    padding: 24px 20px;
  }

  .statistics-overview,
  .statistics-grid {
    grid-template-columns: 1fr;
  }

  .statistics-card {
    padding: 16px 12px;
  }

  .weekly-chart {
    gap: 4px;
  }

  .weekly-chart-column {
    grid-template-rows: 23px 112px auto;
  }

  .weekly-chart-track {
    width: min(70%, 28px);
    height: 106px;
  }

  .weekly-chart-value {
    font-size: 0.58rem;
  }

  .weekly-chart-date {
    font-size: 0.61rem;
  }

  .today-total {
    text-align: left;
  }

  .study-record {
    align-items: flex-start;
    flex-direction: column;
    gap: 8px;
  }

  .record-actions {
    min-width: 0;
    width: 100%;
    justify-content: space-between;
  }

  .record-delete-button {
    min-width: 56px;
    min-height: 44px;
  }

  .history-day-summary {
    padding: 16px;
  }

  .history-day-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 4px;
  }

  .history-record-list {
    padding: 0 16px 12px;
  }

  .background-confirmation-card {
    padding: 24px 20px;
  }

  .background-confirmation-actions {
    grid-template-columns: 1fr;
  }
}

@media (prefers-reduced-motion: reduce) {
  .button {
    transition: none;
  }
}
