:root {
  color-scheme: light;
  --ink: #182322;
  --muted: #60716c;
  --line: #d8e0dc;
  --paper: #fbfaf6;
  --surface: #ffffff;
  --brand: #183d3d;
  --brand-2: #c8523b;
  --sage: #dce8df;
  --gold: #f2c36b;
  --shadow: 0 16px 40px rgba(22, 35, 33, 0.12);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100%;
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(220, 232, 223, 0.95), rgba(251, 250, 246, 0) 360px),
    var(--paper);
}

body.is-locked .app-shell {
  display: none;
}

body.is-locked .lock-screen {
  display: grid;
}

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

button {
  touch-action: manipulation;
}

.app-shell {
  width: min(100%, 780px);
  min-height: 100vh;
  margin: 0 auto;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(28px + env(safe-area-inset-bottom));
}

.lock-screen {
  display: none;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.lock-card {
  width: min(100%, 430px);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 22px;
  background: white;
  box-shadow: var(--shadow);
}

.lock-card h1 {
  margin-bottom: 20px;
  font-size: clamp(2.1rem, 12vw, 4rem);
}

.lock-note {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.lock-error {
  min-height: 1.35em;
  margin: 10px 0 0;
  color: #8f2f24;
  font-weight: 800;
}

.lock-error:not(:empty) {
  padding: 10px 12px;
  border: 1px solid #e2b5aa;
  border-radius: 8px;
  background: #fff4f1;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 8px 0 16px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--brand-2);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

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

h1 {
  font-size: clamp(2rem, 12vw, 4.8rem);
  line-height: 0.95;
}

h2 {
  font-size: 1.35rem;
  line-height: 1.1;
}

h3 {
  margin: 0 0 14px;
  font-size: 1rem;
  letter-spacing: 0;
}

.icon-button {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 52px;
  height: 52px;
  border: 0;
  border-radius: 50%;
  color: white;
  background: var(--brand);
  box-shadow: var(--shadow);
}

.icon-button span {
  transform: translateY(-2px);
  font-size: 2rem;
  line-height: 1;
}

.summary-band {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  overflow: hidden;
  border: 1px solid rgba(24, 61, 61, 0.18);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.78);
  box-shadow: 0 8px 24px rgba(22, 35, 33, 0.08);
}

.summary-band > div {
  min-width: 0;
  padding: 14px 12px;
  border-left: 1px solid var(--line);
}

.summary-band > div:first-child {
  border-left: 0;
}

.summary-label {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 0.76rem;
  font-weight: 700;
}

.summary-band strong {
  font-size: 1.45rem;
}

.tabs {
  position: sticky;
  top: 0;
  z-index: 5;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
  margin: 18px -2px;
  padding: 8px 2px;
  background: rgba(251, 250, 246, 0.92);
  backdrop-filter: blur(14px);
}

.tab {
  min-height: 42px;
  border: 1px solid transparent;
  border-radius: 8px;
  color: var(--muted);
  background: transparent;
  font-size: 0.9rem;
  font-weight: 800;
}

.tab.is-active {
  color: white;
  background: var(--brand);
}

.panel {
  display: none;
}

.panel.is-active {
  display: block;
}

.section-heading {
  margin: 8px 0 18px;
}

label,
fieldset {
  display: block;
  margin: 0 0 16px;
}

label > span,
legend {
  display: block;
  margin-bottom: 7px;
  color: var(--ink);
  font-size: 0.92rem;
  font-weight: 800;
}

input[type="text"],
input[type="date"],
input[type="time"],
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 13px 14px;
  color: var(--ink);
  background: var(--surface);
  outline: none;
  box-shadow: 0 1px 0 rgba(22, 35, 33, 0.04);
}

textarea {
  resize: vertical;
  min-height: 94px;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(24, 61, 61, 0.14);
}

.field-grid {
  display: grid;
  gap: 12px;
}

.field-grid.two {
  grid-template-columns: 1fr 1fr;
}

fieldset {
  min-width: 0;
  border: 0;
  padding: 0;
}

.optional-section {
  margin-top: 12px;
}

.optional-section summary {
  cursor: pointer;
  color: var(--brand);
  font-weight: 900;
}

.optional-section fieldset {
  margin-top: 12px;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.segmented label {
  margin: 0;
}

.segmented input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.segmented span {
  display: grid;
  place-items: center;
  min-height: 46px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.segmented input:checked + span {
  border-color: var(--brand);
  color: white;
  background: var(--brand);
}

.label-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
  font-weight: 800;
}

.inline-action {
  min-height: 30px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 10px;
  color: var(--brand);
  background: white;
  font-size: 0.78rem;
  font-weight: 900;
}

.plan-script-preview {
  margin: -6px 0 14px;
  border: 1px solid rgba(24, 61, 61, 0.18);
  border-radius: 8px;
  padding: 12px;
  color: var(--muted);
  background: white;
}

.plan-script-preview strong {
  display: block;
  margin-bottom: 4px;
  color: var(--ink);
}

.plan-script-preview p {
  margin: 0;
}

.plan-script-preview.is-empty {
  background: rgba(255, 255, 255, 0.62);
}

.plan-start-row {
  position: sticky;
  bottom: calc(10px + env(safe-area-inset-bottom));
  z-index: 2;
  margin-top: 16px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 12px 26px rgba(22, 35, 33, 0.12);
}

.plan-start-row .primary-action {
  width: 100%;
}

.range-anchors {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 800;
}

.range-anchors span:last-child {
  text-align: right;
}

.practice-status {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  border: 1px solid rgba(24, 61, 61, 0.2);
  border-radius: 8px;
  padding: 14px 16px;
  background: white;
}

.practice-status span {
  color: var(--muted);
}

.slider-pair,
.rating-inputs,
.script-editor,
.script-tools,
.script-library-overview,
.script-reader,
.form-group,
.secure-note {
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.slider-pair label:last-child,
.rating-inputs label:last-of-type,
.script-editor label:last-of-type,
.form-group label:last-child,
.form-group fieldset:last-child {
  margin-bottom: 0;
}

.form-group {
  margin-bottom: 16px;
}

.settings-section summary {
  cursor: pointer;
  color: var(--brand);
  font-size: 1rem;
  font-weight: 900;
}

.settings-section[open] summary {
  margin-bottom: 14px;
}

.export-group {
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.export-group:first-of-type {
  padding-top: 0;
  border-top: 0;
}

.export-group + .export-group {
  margin-top: 16px;
}

.export-group h3 {
  margin-bottom: 10px;
  font-size: 0.95rem;
}

.storage-note {
  margin: 14px 0;
}

.backup-group {
  border-color: rgba(24, 61, 61, 0.28);
  background: white;
}

.backup-status,
.small-note {
  margin: 0 0 12px;
  color: var(--muted);
}

.backup-status {
  font-weight: 800;
}

.small-note {
  margin-top: 12px;
  font-size: 0.88rem;
}

.script-tools {
  margin: 16px 0;
  background: rgba(255, 255, 255, 0.62);
}

.script-editor {
  margin-top: 16px;
}

.script-library-overview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 16px;
  background: white;
}

.script-library-overview div:first-child {
  display: grid;
  gap: 4px;
}

.script-library-overview span {
  color: var(--muted);
  font-size: 0.92rem;
}

.script-options {
  margin: 0 0 14px;
}

.script-editor > summary,
.script-options summary,
.script-tools summary {
  cursor: pointer;
  color: var(--brand);
  font-weight: 900;
}

.script-editor > summary {
  margin: -2px 0 12px;
  font-size: 1.05rem;
}

.script-options .field-grid,
.script-tools label:first-of-type {
  margin-top: 12px;
}

.import-text-action {
  margin-top: 12px;
}

.secure-note {
  display: grid;
  gap: 4px;
  margin-bottom: 16px;
  border-color: rgba(24, 61, 61, 0.25);
  background: rgba(220, 232, 223, 0.72);
}

.secure-note span {
  color: var(--muted);
}

.script-reader {
  margin-bottom: 16px;
  background: white;
}

.script-reader summary {
  display: grid;
  gap: 4px;
  cursor: pointer;
  font-weight: 800;
}

.script-reader summary span {
  color: var(--muted);
  font-size: 0.82rem;
}

#selectedScriptBody {
  max-height: 48vh;
  overflow: auto;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
  line-height: 1.55;
  white-space: normal;
}

#selectedScriptBody p {
  margin: 0 0 12px;
}

output {
  float: right;
  min-width: 44px;
  color: var(--brand);
  text-align: right;
  font-weight: 900;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--brand-2);
}

.primary-action,
.secondary-action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  border-radius: 8px;
  padding: 0 16px;
  font-weight: 900;
}

.primary-action {
  width: 100%;
  border: 0;
  color: white;
  background: var(--brand);
}

.secondary-action {
  border: 1px solid var(--brand);
  color: var(--brand);
  background: white;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 8px;
}

.action-row .primary-action,
.action-row .secondary-action,
.action-row .file-action {
  flex: 1 1 150px;
}

.file-action {
  display: inline-grid;
  align-content: center;
  min-height: 48px;
  border: 1px solid var(--brand);
  border-radius: 8px;
  padding: 9px 12px;
  color: var(--brand);
  background: white;
  font-weight: 900;
}

.file-action span {
  margin: 0 0 4px;
  color: var(--brand);
  font-size: 0.86rem;
}

.file-action input {
  max-width: 100%;
  font-size: 0.78rem;
}

.chart-wrap {
  margin: 18px 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px;
  background: white;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
}

.rating-list,
.history-list,
.script-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.script-list {
  margin-top: 16px;
}

.rating-item,
.history-card,
.script-card {
  border: 1px solid var(--line);
  border-left: 5px solid var(--gold);
  border-radius: 8px;
  padding: 12px;
  background: white;
}

.rating-item strong,
.history-card strong,
.script-card strong {
  display: block;
  margin-bottom: 4px;
}

.rating-item p,
.history-card p,
.script-card p {
  margin: 6px 0 0;
  color: var(--muted);
}

.history-card {
  border-left-color: var(--brand-2);
}

.script-card.is-archived {
  opacity: 0.72;
}

.script-card.is-selected {
  border-left-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(24, 61, 61, 0.08);
}

.script-card-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.script-card-head > div {
  min-width: 0;
}

.script-card-head span,
.script-stats span {
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 800;
}

.script-card-head .selected-pill {
  display: inline-block;
  margin-top: 4px;
  border-radius: 999px;
  padding: 3px 8px;
  color: white;
  background: var(--brand);
}

.tag-row,
.script-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}

.tag-row span {
  border: 1px solid rgba(24, 61, 61, 0.16);
  border-radius: 999px;
  padding: 4px 8px;
  color: var(--brand);
  background: var(--sage);
  font-size: 0.78rem;
  font-weight: 800;
}

.script-reader-tags {
  margin: 0 0 12px;
}

.history-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.small-button {
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 12px;
  color: var(--ink);
  background: var(--sage);
  font-weight: 800;
}

.primary-small {
  border-color: var(--brand);
  color: white;
  background: var(--brand);
}

.danger-button {
  color: #8f2f24;
  background: #f8e0dc;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: calc(16px + env(safe-area-inset-bottom));
  left: 16px;
  transform: translateY(120%);
  max-width: 520px;
  margin: 0 auto;
  border-radius: 8px;
  padding: 13px 16px;
  color: white;
  background: var(--brand);
  box-shadow: var(--shadow);
  opacity: 0;
  transition: transform 180ms ease, opacity 180ms ease;
}

.toast.is-visible {
  transform: translateY(0);
  opacity: 1;
}

@media (max-width: 420px) {
  .app-shell {
    padding-right: 12px;
    padding-left: 12px;
  }

  .field-grid.two {
    grid-template-columns: 1fr;
  }

  .summary-label {
    min-height: 2.1em;
  }

  .summary-band strong {
    font-size: 1.2rem;
  }

  .script-library-overview,
  .script-card-head {
    display: grid;
  }

  .script-library-overview .action-row,
  .history-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .tab {
    font-size: 0.68rem;
    padding: 0 2px;
  }
}

@media print {
  body {
    background: white;
  }

  .topbar,
  .summary-band,
  .tabs,
  .action-row,
  .toast {
    display: none;
  }

  .app-shell {
    width: 100%;
    padding: 0;
  }

  .panel {
    display: block;
  }
}
