/* Review Studio — thai-kon design language (98.Personal/thai-kon/DESIGN.md, adopted 2026-07-29).
   Peach canvas, navy ink and committed state, coral for judgement/active, sage only when
   something is right. Fraunces speaks; Sarabun carries UI and Thai in one family. */

:root {
  color-scheme: light;
  --tk-peach-50: #faf2e8;
  --tk-peach-100: #f4e6d8;
  --tk-peach-200: #ecd6c0;
  --tk-peach-300: #d9b896;
  --tk-navy-700: #2a2660;
  --tk-navy-800: #1d1a4f;
  --tk-navy-900: #14123d;
  --tk-coral-400: #e87a5d;
  --tk-coral-500: #d8634a;
  --tk-sage-500: #5e8c66;
  --tk-sage-600: #4a7556;
  --tk-warm-600: #6c5f55;
  --tk-warm-700: #4f463d;
  --tk-serif: Fraunces, Georgia, "Times New Roman", serif;
  --font-ui: Sarabun, Thonburi, "Noto Sans Thai", -apple-system, BlinkMacSystemFont,
    "Segoe UI", sans-serif;
  --font-thai: var(--font-ui);
  --rail-width: 200px;
  --tabbar-height: 64px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--tk-peach-100);
  color: var(--tk-navy-800);
  font-family: var(--font-ui);
  font-size: 14px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
  padding: 18px 24px;
}

h1,
h2,
p {
  margin: 0;
}

/* The wordmark speaks serif, like thai-kon's own. */
h1 {
  font-family: var(--tk-serif);
  font-feature-settings: "ss01", "ss02";
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.01em;
  line-height: 1.05;
  color: var(--tk-navy-800);
}

h2 {
  font-family: var(--font-thai);
  font-size: 21px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--tk-navy-800);
}

p,
label,
span,
.meta {
  color: var(--tk-warm-600);
  font-size: 13px;
  line-height: 1.5;
}

label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* ---- The five destinations: rail on desktop, bottom bar on mobile ---- */

.tabbar {
  position: fixed;
  z-index: 3;
  display: flex;
  background: rgba(244, 230, 216, 0.95);
  backdrop-filter: blur(10px);
}

.tabbar button {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  min-height: 52px;
  padding: 6px 8px;
  border: 0;
  background: transparent;
  color: var(--tk-warm-600);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.tabbar svg {
  width: 22px;
  height: 22px;
}

.tabbar button.is-active {
  color: var(--tk-navy-800);
}

.tabbar button.is-active svg {
  color: var(--tk-coral-500);
}

/* Library's show sub-items: desktop rail only (Grok/Airtable indent pattern) —
   an indent rule, quiet labels, a coral tick on the active shelf. */
.rail-shows {
  display: none;
}

@media (min-width: 781px) {
  body[data-mode="library"] .rail-shows {
    display: grid;
    gap: 1px;
    margin: 2px 0 6px 22px;
    padding-left: 12px;
    border-left: 1px solid var(--tk-peach-200);
  }

  .rail-shows button {
    min-height: 30px;
    padding: 4px 8px;
    border: 0;
    border-radius: 8px;
    background: transparent;
    color: var(--tk-warm-600);
    font-size: 12px;
    font-weight: 400;
    text-align: left;
    text-transform: none;
    letter-spacing: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .rail-shows button.is-active {
    color: var(--tk-navy-800);
    font-weight: 600;
  }

  .rail-shows button.is-active::before {
    content: "";
    display: inline-block;
    width: 5px;
    height: 5px;
    margin-right: 7px;
    border-radius: 999px;
    background: var(--tk-coral-500);
    vertical-align: middle;
  }
}

/* Drill-in show list — Library's front door on mobile, the overflow view on desktop. */
.show-list {
  display: grid;
  gap: 8px;
  max-width: 520px;
}

.show-list button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 52px;
  padding: 10px 16px;
  border-radius: 14px;
  text-align: left;
}

.show-list .show-name {
  color: var(--tk-navy-800);
  font-size: 15px;
  font-weight: 600;
}

.show-list .show-count {
  color: var(--tk-warm-600);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
}

.library-scope-bar {
  display: flex;
  align-items: center;
  gap: 12px;
}

.library-scope-bar button {
  width: auto;
  min-height: 32px;
  padding: 2px 12px;
  border-color: rgba(232, 122, 93, 0.4);
  background: transparent;
  color: var(--tk-coral-500);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.library-scope-label {
  color: var(--tk-navy-800);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

@media (min-width: 781px) {
  .tabbar {
    top: 0;
    bottom: auto;
    left: 0;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    width: var(--rail-width);
    height: 100vh;
    padding: 88px 12px 16px;
    border-right: 1px solid var(--tk-peach-200);
    background: transparent;
    backdrop-filter: none;
  }

  .tabbar button {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    min-height: 42px;
    padding: 8px 12px;
    border-radius: 12px;
    font-size: 12px;
  }

  .tabbar button.is-active {
    background: var(--tk-peach-50);
  }

  header,
  main {
    margin-left: var(--rail-width);
  }
}

@media (max-width: 780px) {
  .tabbar {
    right: 0;
    bottom: 0;
    left: 0;
    justify-content: space-around;
    height: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
    padding: 4px 8px env(safe-area-inset-bottom);
    border-top: 1px solid var(--tk-peach-200);
  }

  body {
    padding-bottom: calc(var(--tabbar-height) + env(safe-area-inset-bottom));
  }
}

/* ---- Content area ---- */

main {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: calc(100vh - 76px);
}

/* Only Library keeps its sidebar; everything else goes full-width. Profile is the one
   statically-marked surface — the others render into #items. */
body:not([data-mode="library"]) main {
  display: block;
}

body:not([data-mode="library"]) aside {
  display: none;
}

body:not([data-mode="profile"]) .profile {
  display: none;
}

/* The drill-in show list answers "which shelf" — search/filters belong to the rows
   behind it, so they hide until a shelf is picked. */
body[data-library-view="shows"] aside {
  display: none;
}

body[data-mode="profile"] .library {
  display: none;
}

.profile {
  display: grid;
  gap: 16px;
  max-width: 520px;
  margin: 12px auto 0;
  padding: 0 24px 48px;
}

.profile-card {
  padding: 18px 20px;
  border: 1px solid var(--tk-peach-200);
  border-radius: 16px;
  background: var(--tk-peach-50);
}

.profile-email {
  color: var(--tk-navy-800);
  font-size: 16px;
  font-weight: 600;
}

/* Sage only when something is right — signed out reads warm. */
#accountSync {
  margin-top: 4px;
  color: var(--tk-warm-600);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

#accountSync.is-synced {
  color: var(--tk-sage-600);
}

.profile-rows {
  display: grid;
  gap: 8px;
}

/* Same specificity trap as #signin: our display rule outranks the UA [hidden] rule. */
.profile-rows button[hidden] {
  display: none;
}

.profile-rows button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 52px;
  padding: 10px 16px;
  border-radius: 14px;
  text-align: left;
}

.profile-row-note {
  color: inherit;
  opacity: 0.75;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.profile-install-note {
  text-align: center;
}

/* Danger zone: set apart from the ordinary profile rows, not blended into them. */
.danger-zone {
  display: grid;
  gap: 8px;
  padding-top: 8px;
  border-top: 1px solid var(--tk-peach-200);
}

button.danger {
  border-color: var(--tk-coral-500);
  color: var(--tk-coral-500);
  background: transparent;
}

button.danger:active:not(:disabled) {
  background: rgba(216, 99, 74, 0.12);
}

@media (hover: hover) {
  button.danger:hover:not(:disabled) {
    background: rgba(216, 99, 74, 0.08);
  }
}

#deleteConfirm[hidden] {
  display: none;
}

/* ---- Today ---- */

.today {
  display: grid;
  gap: 16px;
  max-width: 520px;
  margin: 12px auto 0;
}

/* The one navy card — the day's commitment. */
.today-hero {
  display: grid;
  gap: 4px;
  padding: 26px 24px;
  border-radius: 20px;
  background: var(--tk-navy-800);
  color: var(--tk-peach-50);
}

.today-count {
  font-family: var(--tk-serif);
  font-feature-settings: "ss01", "ss02";
  font-size: 44px;
  font-weight: 600;
  line-height: 1;
  color: var(--tk-peach-50);
}

.today-sub {
  color: var(--tk-peach-50);
  opacity: 0.85;
}

.today-hero [data-today-action="start"] {
  margin-top: 14px;
  min-height: 48px;
  border-color: var(--tk-peach-50);
  border-radius: 16px;
  background: var(--tk-peach-50);
  color: var(--tk-navy-800);
}

.today-recent {
  display: grid;
  gap: 8px;
}

.today-recent-head {
  color: var(--tk-warm-600);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.today-recent-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border: 1px solid var(--tk-peach-200);
  border-radius: 14px;
  background: var(--tk-peach-50);
}

.today-recent-thai {
  color: var(--tk-navy-800);
  font-size: 17px;
  font-weight: 600;
}

.today-recent-paiboon {
  color: var(--tk-warm-600);
  font-size: 11px;
  font-style: italic;
}

.today-recent-source {
  flex: 0 0 auto;
  color: var(--tk-warm-600);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

aside {
  padding: 20px;
}

section + section {
  margin-top: 20px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
}

.metrics div {
  padding: 12px 10px;
  border: 1px solid var(--tk-peach-200);
  border-radius: 12px;
  background: var(--tk-peach-50);
}

.metrics span {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

strong {
  display: block;
  color: var(--tk-navy-800);
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.controls,
.fields {
  display: grid;
  gap: 8px;
}

/* The .controls display above outranks the browser's [hidden] rule, so the sign-in panel needs
   an id-weighted selector or it can never hide. */
#signin[hidden] {
  display: none;
}

#signin {
  padding: 16px;
  border: 1px solid var(--tk-peach-200);
  border-radius: 16px;
  background: var(--tk-peach-50);
}

input,
select,
textarea,
button {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--tk-peach-200);
  color: var(--tk-navy-800);
  font: inherit;
}

/* Checkboxes opt out of the universal input sizing above — a checkbox stretched to 100%/40px
   renders as an oversized box, not a control. */
input[type="checkbox"] {
  width: auto;
  min-height: auto;
}

.consent-row {
  display: grid;
  gap: 10px;
  margin-bottom: 4px;
}

.checkbox-row {
  display: flex;
  align-items: start;
  gap: 8px;
  text-transform: none;
  letter-spacing: normal;
  font-size: 12px;
  font-weight: 400;
}

.checkbox-row input {
  margin-top: 2px;
}

.checkbox-row a {
  color: var(--tk-coral-500);
}

input,
select,
textarea {
  padding: 8px 12px;
  border-radius: 12px;
  background: var(--tk-peach-50);
}

input::placeholder,
textarea::placeholder {
  color: var(--tk-peach-300);
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--tk-coral-400);
  outline: 2px solid rgba(232, 122, 93, 0.25);
  outline-offset: 0;
}

textarea {
  border-radius: 12px;
  resize: vertical;
}

button {
  padding: 0 14px;
  border-radius: 12px;
  background: var(--tk-peach-50);
  cursor: pointer;
  font-weight: 600;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

/* thai-kon: pressed feedback is a background shift, never movement. */
button:active:not(:disabled) {
  background: var(--tk-peach-200);
}

button:focus-visible {
  outline: 2px solid var(--tk-coral-500);
  outline-offset: 2px;
}

button:disabled {
  color: var(--tk-peach-300);
  cursor: default;
}

/* Primary actions are navy, the committed state. Filled surfaces carry peach-50, never white. */
#export,
[data-action="save"],
#submitPassword {
  border-color: var(--tk-navy-800);
  background: var(--tk-navy-800);
  color: var(--tk-peach-50);
  font-weight: 600;
}

#export:active,
[data-action="save"]:active,
#submitPassword:active {
  background: var(--tk-navy-700);
}

@media (hover: hover) {
  #export:hover,
  [data-action="save"]:hover,
  #submitPassword:hover {
    background: var(--tk-navy-700);
  }
}

header button {
  width: auto;
  min-height: 42px;
  padding: 0 20px;
  border-radius: 14px;
}

.library {
  padding: 20px 24px 48px;
}

.items {
  display: grid;
  gap: 12px;
  max-width: 880px;
}

.empty {
  padding: 40px 24px;
  border: 1px dashed var(--tk-peach-300);
  border-radius: 16px;
  color: var(--tk-warm-600);
  font-family: var(--tk-serif);
  font-size: 15px;
  font-style: italic;
  text-align: center;
}

.item {
  padding: 18px 20px 20px;
  border: 1px solid var(--tk-peach-200);
  border-radius: 16px;
  background: var(--tk-peach-50);
}

.item-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 14px;
}

/* State descriptions are uppercase micro-labels — thai-kon's secondary voice. */
.badge {
  flex: 0 0 auto;
  padding: 4px 10px;
  border: 1px solid var(--tk-peach-200);
  border-radius: 999px;
  background: transparent;
  color: var(--tk-warm-600);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* Coral is judgement: a due card asks for it. */
.badge-due,
.item-due .badge {
  border-color: var(--tk-coral-500);
  background: var(--tk-coral-500);
  color: var(--tk-peach-50);
}

.sentence {
  margin-top: 10px;
}

.thai {
  color: var(--tk-navy-800);
  font-family: var(--font-thai);
  font-size: 18px;
  font-weight: 600;
}

.english {
  color: var(--tk-warm-600);
}

.fields {
  grid-template-columns: 1fr 1fr;
  gap: 10px 12px;
  margin-top: 16px;
}

/* Library rows fold their correction fields behind a tap on the row head. */
.item[data-key] .item-head {
  cursor: pointer;
}

.item[data-key]:not(.is-expanded) .fields,
.item[data-key]:not(.is-expanded) .item-actions {
  display: none;
}

.fields label:last-child {
  grid-column: 1 / -1;
}

.fields label {
  display: grid;
  gap: 6px;
}

.item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 16px;
}

.item-actions button {
  width: auto;
  padding: 0 16px;
}

/* ---- Study — one card, recall first ---- */

.study-card {
  display: grid;
  gap: 14px;
  max-width: 520px;
  margin: 12px auto 0;
  padding: 0;
  border: 0;
  background: transparent;
}

.study-progress {
  height: 2px;
  border-radius: 999px;
  background: var(--tk-peach-200);
}

.study-progress span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: var(--tk-coral-500);
}

.study-count {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.study-thai {
  margin-top: 10px;
  font-size: 40px;
  font-weight: 600;
  line-height: 1.15;
  color: var(--tk-navy-800);
}

.study-context {
  margin: 0;
  font-weight: 400;
}

.study-reveal-zone {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

[data-study-action="reveal"] {
  min-height: 48px;
  border-radius: 16px;
  border-color: var(--tk-navy-800);
  background: var(--tk-navy-800);
  color: var(--tk-peach-50);
}

.study-paiboon {
  margin: 0;
  color: var(--tk-warm-600);
  font-size: 14px;
  font-style: italic;
}

/* The meaning speaks serif, in sage — the "you were right to wonder" voice. */
.study-meaning {
  margin: 0;
  color: var(--tk-sage-600);
  font-family: var(--tk-serif);
  font-feature-settings: "ss01", "ss02";
  font-size: 22px;
  font-weight: 500;
}

.study-ratings {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.study-ratings button {
  width: auto;
  flex: 1 1 40%;
  min-height: 46px;
  border-radius: 14px;
  font-size: 12px;
}

.study-empty button {
  width: auto;
  margin-top: 12px;
  padding: 0 18px;
  font-style: normal;
}

/* ---- Sentence Lab — the reference thai-kon surface ---- */

.lab-card {
  display: grid;
  gap: 18px;
  padding: 4px 0 0;
  border: 0;
  background: transparent;
}

.lab-card h2 {
  font-family: var(--tk-serif);
  font-feature-settings: "ss01", "ss02";
  font-size: 22px;
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--tk-navy-800);
}

.lab-card .meta {
  color: var(--tk-warm-600);
}

.lab-card .badge {
  border-color: var(--tk-peach-200);
  background: var(--tk-peach-50);
  color: var(--tk-warm-600);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

/* The answer line is a writing line, not a box. */
.lab-answer {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  min-height: 84px;
  padding: 0 0 14px;
  border: 0;
  border-bottom: 1px solid var(--tk-peach-300);
  border-radius: 0;
  background: transparent;
}

.lab-empty-hint {
  align-self: center;
  margin: 0;
  color: rgba(108, 95, 85, 0.6);
  font-family: var(--tk-serif);
  font-size: 14px;
  font-style: italic;
}

.lab-hint-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 32px;
}

.lab-hint-row .english {
  margin: 0;
  color: var(--tk-warm-700);
}

.lab-hint-row button {
  width: auto;
  min-height: 30px;
  padding: 2px 14px;
  border-color: rgba(232, 122, 93, 0.4);
  background: transparent;
  color: var(--tk-coral-500);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.lab-hint-row [data-lab-action="listen"] {
  margin-left: auto;
}

.lab-token-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.lab-token {
  width: auto;
  min-width: 44px;
  min-height: 52px;
  padding: 6px 14px;
  border-radius: 12px;
  border-color: var(--tk-peach-200);
  background: var(--tk-peach-50);
  color: var(--tk-navy-800);
  font-family: var(--font-thai);
}

.lab-token-text,
.lab-token-paiboon {
  display: block;
}

.lab-token-text,
.lab-token-text span {
  color: inherit;
  font-size: 18px;
  line-height: 1.2;
}

.lab-token-paiboon {
  margin-top: 2px;
  color: currentColor;
  opacity: 0.7;
  font-size: 11px;
  font-style: italic;
  line-height: 1.1;
}

/* Committed chips land navy; pressing one returns it to the pool. */
.lab-answer .lab-token {
  border-color: var(--tk-navy-800);
  background: var(--tk-navy-800);
  color: var(--tk-peach-50);
}

/* Ghost slot: the picked chip's empty outline keeps its place on the board. */
.lab-ghost,
.lab-ghost:disabled {
  border: 1px solid rgba(217, 184, 150, 0.7);
  background: transparent;
  color: transparent;
}

.lab-controls [data-lab-action="check"] {
  flex: 1;
  min-height: 48px;
  border-radius: 16px;
  border-color: var(--tk-navy-800);
  background: var(--tk-navy-800);
  color: var(--tk-peach-50);
}

.lab-controls [data-lab-action="check"]:disabled {
  border-color: var(--tk-peach-300);
  background: var(--tk-peach-300);
  color: var(--tk-peach-100);
}

.lab-controls [data-lab-action="reset"],
.lab-controls [data-lab-action="next"] {
  border-color: var(--tk-peach-200);
  background: var(--tk-peach-50);
  color: var(--tk-navy-800);
}

/* Verdict panel: sage when right, navy when not. The only strong surface in the card. */
.lab-feedback {
  display: grid;
  gap: 10px;
  padding: 20px;
  border: 0;
  border-radius: 20px;
  background: var(--tk-navy-800);
  color: var(--tk-peach-50);
}

.lab-feedback[hidden] {
  display: none;
}

.lab-feedback.lab-correct {
  background: var(--tk-sage-600);
}

.lab-verdict {
  margin: 0;
  color: var(--tk-peach-50);
  font-family: var(--tk-serif);
  font-feature-settings: "ss01", "ss02";
  font-size: 20px;
  font-weight: 500;
}

.lab-feedback .thai {
  margin: 0;
  color: var(--tk-peach-50);
  font-size: 20px;
  font-weight: 500;
}

.lab-ratings {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 6px;
}

.lab-ratings button {
  width: auto;
  flex: 1;
  min-height: 44px;
  border-color: var(--tk-peach-50);
  border-radius: 14px;
  background: var(--tk-peach-50);
  color: var(--tk-navy-800);
}

.lab-ratings button:disabled {
  opacity: 0.55;
  color: var(--tk-navy-800);
}

@media (max-width: 780px) {
  header {
    padding: 16px;
  }

  header button {
    min-height: 40px;
    padding: 0 14px;
    font-size: 12px;
  }

  main {
    display: block;
  }

  aside {
    padding: 16px;
  }

  .library {
    padding: 16px 16px 40px;
  }

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