:root,
html[data-theme="dark"] {
  color-scheme: dark;
  --paper: #0f1110;
  --surface: #171918;
  --field: #111311;
  --ink: #f0ebe0;
  --muted: #aaa498;
  --rule: #363934;
  --control: #6c6b63;
  --accent: #d38b64;
  --accent-soft: rgba(211, 139, 100, 0.16);
  --hover: #1b1e1c;
  --success: #9bc2a6;
  --danger: #e39a8b;
  --button-text: #151714;
  --page-width: 920px;
  --tool-width: 960px;
  --font-sans: -apple-system, BlinkMacSystemFont, "Helvetica Neue", "Segoe UI", Arial, sans-serif;
  --font-serif: "Iowan Old Style", Baskerville, "Palatino Linotype", Georgia, serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

html[data-theme="light"] {
  color-scheme: light;
  --paper: #f3eee3;
  --surface: #faf7ef;
  --field: #fffaf1;
  --ink: #1d1c19;
  --muted: #676158;
  --rule: #cfc5b5;
  --control: #81796d;
  --accent: #9b4b31;
  --accent-soft: rgba(155, 75, 49, 0.12);
  --hover: #ece4d7;
  --success: #276447;
  --danger: #98382f;
  --button-text: #faf7ef;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font-sans);
  font-size: 16px;
  line-height: 1.55;
  transition: background-color 160ms ease, color 160ms ease;
  -webkit-font-smoothing: antialiased;
}

::selection {
  background: var(--accent);
  color: var(--paper);
}

button,
input,
select {
  font: inherit;
}

a {
  color: inherit;
}

button,
a,
input,
select,
summary {
  outline: none;
}

button:focus-visible,
a:focus-visible,
input:focus-visible,
select:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 3px;
}

[hidden] {
  display: none !important;
}

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

.skip-link {
  position: fixed;
  z-index: 20;
  top: 0.75rem;
  left: 0.75rem;
  padding: 0.7rem 0.9rem;
  background: var(--ink);
  color: var(--paper);
  font-weight: 600;
  text-decoration: none;
  transform: translateY(-160%);
}

.skip-link:focus {
  transform: translateY(0);
}

.site-page,
.tool-page {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.container {
  width: min(calc(100% - 4rem), var(--page-width));
  margin-inline: auto;
}

.site-header,
.tool-header {
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  transition: background-color 160ms ease, border-color 160ms ease;
}

.header-inner,
.tool-nav-inner {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: space-between;
  gap: 1.25rem;
}

.site-name {
  font-size: 0.92rem;
  font-weight: 650;
  letter-spacing: -0.01em;
  text-decoration: none;
}

.site-nav {
  display: flex;
  align-items: center;
  gap: 1.35rem;
}

.site-nav a,
.footer-link,
.back-link,
.theme-toggle {
  color: var(--muted);
  font-size: 0.82rem;
  text-underline-offset: 0.22em;
  white-space: nowrap;
}

.theme-toggle {
  display: none;
  min-width: 44px;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0 0.15rem;
  border: 0;
  border-bottom: 1px solid var(--control);
  background: transparent;
  cursor: pointer;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.theme-enabled .theme-toggle {
  display: inline-flex;
}

.home-main {
  flex: 1;
}

.intro {
  padding: 5.2rem 0 4.2rem;
  border-bottom: 1px solid var(--rule);
}

.intro-label,
.tool-label {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 0 0 1rem;
  color: var(--accent);
  font-family: var(--font-sans);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.intro-label::after,
.tool-label::after {
  width: 2.5rem;
  height: 1px;
  background: var(--accent);
  content: "";
}

.intro h1 {
  margin: 0;
  max-width: 790px;
  font-family: var(--font-serif);
  font-size: clamp(4.2rem, 9vw, 6.4rem);
  font-weight: 400;
  letter-spacing: -0.055em;
  line-height: 0.92;
}

.intro-copy {
  max-width: 650px;
  margin: 2rem 0 0;
  color: var(--muted);
  font-size: 1.02rem;
  line-height: 1.75;
}

.projects {
  padding: 3.2rem 0 4.5rem;
}

.projects h2 {
  margin: 0 0 1.25rem;
  color: var(--accent);
  font-size: 0.76rem;
  font-weight: 700;
  letter-spacing: 0.11em;
  text-transform: uppercase;
}

.project-list {
  padding: 0;
  margin: 0;
  border-bottom: 1px solid var(--rule);
  list-style: none;
}

.project-item {
  border-top: 1px solid var(--rule);
}

.project-link {
  display: grid;
  min-height: 112px;
  align-items: center;
  padding: 1.45rem 0.55rem;
  margin-inline: -0.55rem;
  text-decoration: none;
  grid-template-columns: 54px minmax(175px, 0.72fr) minmax(0, 1.55fr) 145px 24px;
  gap: 1.2rem;
  transition: background-color 140ms ease, color 140ms ease;
}

.project-index {
  color: var(--accent);
  font-family: var(--font-serif);
  font-size: 1.45rem;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.project-name {
  margin: 0;
  font-family: var(--font-serif);
  font-size: 1.3rem;
  font-weight: 400;
  letter-spacing: -0.02em;
  line-height: 1.2;
  transition: color 140ms ease;
}

.project-description {
  margin: 0;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.55;
}

.project-meta {
  margin: 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.76rem;
  line-height: 1.55;
  text-align: right;
}

.project-arrow {
  color: var(--accent);
  font-size: 1.05rem;
  text-align: right;
  transition: transform 140ms ease;
}

.privacy-note {
  display: flex;
  max-width: 650px;
  align-items: baseline;
  gap: 0.7rem;
  margin: 1.5rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.privacy-note::before {
  width: 0.42rem;
  height: 0.42rem;
  flex: 0 0 auto;
  background: var(--accent);
  content: "";
}

.site-footer {
  margin-top: auto;
  border-top: 1px solid var(--rule);
}

.footer-inner {
  display: flex;
  min-height: 72px;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

/* Tool pages */
.tool-nav-inner {
  width: min(calc(100% - 4rem), var(--tool-width));
  margin-inline: auto;
}

.back-link {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  text-decoration: none;
}

.tool-main {
  display: grid;
  width: min(calc(100% - 4rem), var(--tool-width));
  margin-inline: auto;
  padding: 4.5rem 0 5rem;
  align-items: start;
  grid-template-columns: 250px minmax(0, 1fr);
  gap: 3.5rem;
}

.tool-heading {
  padding-top: 0.25rem;
}

.tool-label {
  margin-bottom: 0.9rem;
}

.tool-heading h1 {
  margin: 0;
  font-family: var(--font-serif);
  font-size: clamp(2.8rem, 5vw, 3.2rem);
  font-weight: 400;
  letter-spacing: -0.05em;
  line-height: 0.98;
}

.tool-heading > p:not(.tool-label) {
  margin: 1.25rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.7;
}

.tool-surface {
  padding: 1.8rem;
  border: 1px solid var(--rule);
  border-top: 2px solid var(--accent);
  border-radius: 2px;
  background: var(--surface);
  transition: background-color 160ms ease, border-color 160ms ease;
}

.grade-column-heads,
.grade-row {
  display: grid;
  align-items: center;
  grid-template-columns: minmax(0, 1fr) minmax(0, 0.72fr) 42px;
  gap: 0.65rem;
}

.grade-column-heads {
  padding: 0 0.1rem 0.5rem;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.grade-rows {
  display: grid;
  gap: 0.7rem;
}

.form-control {
  width: 100%;
  min-width: 0;
  min-height: 46px;
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--control);
  border-radius: 1px;
  background: var(--field);
  color: var(--ink);
  font-size: 16px;
  transition: background-color 160ms ease, border-color 130ms ease, box-shadow 130ms ease, color 160ms ease;
}

.form-control::placeholder {
  color: var(--muted);
  opacity: 0.82;
}

.form-control:focus-visible {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft);
}

input[type="time"].form-control {
  max-width: 100%;
}

@supports (-webkit-touch-callout: none) {
  input[type="time"].form-control {
    padding-inline: 0;
  }
}

.icon-button {
  display: inline-flex;
  width: 42px;
  height: 42px;
  align-items: center;
  justify-content: center;
  padding: 0;
  border: 1px solid var(--rule);
  border-radius: 1px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.2rem;
  line-height: 1;
}

.form-hint {
  margin: 0.9rem 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.form-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.2rem;
}

.button {
  display: inline-flex;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  padding: 0.65rem 1rem;
  border: 1px solid var(--ink);
  border-radius: 1px;
  background: var(--ink);
  color: var(--button-text);
  cursor: pointer;
  font-size: 0.84rem;
  font-weight: 650;
  text-decoration: none;
  transition: background-color 130ms ease, border-color 130ms ease, color 130ms ease;
}

.button--secondary {
  border-color: var(--control);
  background: transparent;
  color: var(--ink);
}

.button--text {
  min-height: 44px;
  padding-inline: 0.2rem;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-color: var(--rule);
  text-underline-offset: 0.22em;
}

.message {
  margin: 0.95rem 0 0;
  color: var(--danger);
  font-size: 0.82rem;
  font-weight: 650;
}

.message:empty {
  display: none;
}

.inline-result {
  margin-top: 1.55rem;
  padding-top: 1.4rem;
  border-top: 1px solid var(--rule);
}

.result-line {
  display: flex;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 0.7rem 1.1rem;
}

.result-value,
.result-time {
  color: var(--ink);
  font-family: var(--font-serif);
  font-variant-numeric: tabular-nums;
  font-size: clamp(3.2rem, 9vw, 4.3rem);
  font-weight: 400;
  letter-spacing: -0.055em;
  line-height: 0.92;
}

.result-status {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 650;
}

.result-status::before {
  width: 0.48rem;
  height: 0.48rem;
  border-radius: 50%;
  background: var(--muted);
  content: "";
}

.result-status[data-tone="success"] {
  color: var(--success);
}

.result-status[data-tone="success"]::before {
  background: var(--success);
}

.result-status[data-tone="danger"] {
  color: var(--danger);
}

.result-status[data-tone="danger"]::before {
  background: var(--danger);
}

.result-summary {
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.planner {
  margin-top: 1.55rem;
  padding-top: 1.2rem;
  border-top: 1px solid var(--rule);
}

.planner summary {
  width: fit-content;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 650;
}

.planner-grid {
  display: grid;
  margin-top: 1rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem;
}

.form-label {
  display: block;
  margin-bottom: 0.4rem;
  font-size: 0.78rem;
  font-weight: 650;
}

.planner-output {
  display: block;
  margin-top: 0.9rem;
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 650;
}

.planner-output[data-tone="success"] {
  color: var(--success);
}

.planner-output[data-tone="danger"] {
  color: var(--danger);
}

.mode-list {
  display: grid;
  padding: 0 0 1.25rem;
  margin: 0 0 1.4rem;
  border: 0;
  border-bottom: 1px solid var(--rule);
  gap: 0.35rem;
}

.mode-choice {
  display: flex;
  min-height: 44px;
  align-items: center;
  gap: 0.7rem;
  cursor: pointer;
}

.mode-choice input {
  width: 1rem;
  height: 1rem;
  margin: 0;
  accent-color: var(--accent);
}

.mode-choice span {
  font-size: 0.9rem;
}

.sleep-fields {
  display: grid;
  gap: 0.85rem;
}

.field-row {
  display: grid;
  align-items: center;
  grid-template-columns: 165px minmax(0, 1fr);
  gap: 1rem;
}

.field-row .form-label {
  margin: 0;
}

.submit-row {
  margin-top: 1.4rem;
}

.submit-row .button {
  width: 100%;
}

.result-caption {
  margin: 0 0 0.5rem;
  color: var(--accent);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.disclaimer {
  grid-column: 2;
  margin: -2.5rem 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

@media (hover: hover) {
  .site-name:hover,
  .site-nav a:hover,
  .footer-link:hover,
  .back-link:hover,
  .theme-toggle:hover {
    color: var(--accent);
  }

  .project-link:hover {
    background: var(--hover);
  }

  .project-link:hover .project-name {
    color: var(--accent);
  }

  .project-link:hover .project-arrow {
    transform: translateX(3px);
  }

  .button:hover {
    border-color: var(--accent);
    background: var(--accent);
    color: var(--paper);
  }

  .button--secondary:hover,
  .button--text:hover {
    border-color: var(--accent);
    background: transparent;
    color: var(--accent);
  }

  .icon-button:hover {
    border-color: var(--accent);
    color: var(--accent);
  }
}

@media (max-width: 820px) {
  .tool-main {
    display: block;
    width: min(calc(100% - 3rem), 700px);
    padding: 3rem 0 4rem;
  }

  .tool-nav-inner {
    width: min(calc(100% - 3rem), 700px);
  }

  .tool-heading {
    margin-bottom: 1.7rem;
  }

  .tool-heading > p:not(.tool-label) {
    max-width: 580px;
    margin-top: 1rem;
  }

  .disclaimer {
    margin: 1rem 0 0;
  }
}

@media (max-width: 720px) {
  .container {
    width: min(calc(100% - 2.5rem), var(--page-width));
  }

  .header-inner,
  .tool-nav-inner {
    min-height: 60px;
  }

  .projects-nav-link {
    display: none;
  }

  .intro {
    padding: 3.4rem 0 3rem;
  }

  .intro h1 {
    font-size: clamp(3.2rem, 15vw, 4.7rem);
  }

  .intro-copy {
    margin-top: 1.5rem;
    font-size: 0.96rem;
  }

  .projects {
    padding: 2.5rem 0 3.4rem;
  }

  .project-link {
    min-height: 0;
    padding: 1.35rem 0.25rem;
    margin-inline: -0.25rem;
    grid-template-columns: 42px minmax(0, 1fr) 24px;
    gap: 0.45rem 0.85rem;
  }

  .project-index {
    grid-column: 1;
    grid-row: 1;
    font-size: 1.25rem;
  }

  .project-name {
    grid-column: 2;
    grid-row: 1;
    font-size: 1.25rem;
  }

  .project-description {
    grid-column: 2 / -1;
    grid-row: 2;
  }

  .project-meta {
    grid-column: 2 / -1;
    grid-row: 3;
    margin-top: 0.2rem;
    text-align: left;
  }

  .project-arrow {
    grid-column: 3;
    grid-row: 1;
  }

  .footer-inner {
    min-height: 66px;
  }

  .tool-heading h1 {
    font-size: 3rem;
  }

  .tool-surface {
    padding: 1.3rem;
  }

  .field-row {
    grid-template-columns: 1fr;
    gap: 0.4rem;
  }
}

@media (max-width: 480px) {
  .container,
  .tool-main,
  .tool-nav-inner {
    width: min(calc(100% - 2rem), var(--page-width));
  }

  .site-nav {
    gap: 0.85rem;
  }

  .intro h1 {
    font-size: clamp(3rem, 16vw, 4rem);
  }

  .grade-column-heads,
  .grade-row {
    grid-template-columns: minmax(0, 1fr) minmax(0, 0.72fr) 40px;
    gap: 0.42rem;
  }

  .icon-button {
    width: 40px;
    height: 40px;
  }

  .form-actions {
    align-items: stretch;
    flex-direction: column;
  }

  .form-actions .button {
    width: 100%;
  }

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

@media (max-width: 350px) {
  .site-name {
    font-size: 0.84rem;
  }

  .site-nav {
    gap: 0.6rem;
  }

  .site-nav a,
  .theme-toggle {
    font-size: 0.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
