/* ───────────────────────────────────────────────────────────────────────
   Finley Talk — sticker-book interface
   Words are plump sticker pills on warm cream paper. Colours follow the
   Fitzgerald Key (the AAC convention Grid uses too):
     yellow people · green doing · orange things · blue describing
     pink social · purple questions · red no/stop · grey little words
   ─────────────────────────────────────────────────────────────────────── */

:root {
  --bg: #fff7ec;
  --paper-dot: rgba(124, 94, 42, 0.05);
  --ink: #4a3520;
  --ink-soft: #a08c6c;
  --card: #fffdf7;
  --edge: #f2e7d2;

  --pronoun-b: #ffc81e;  --pronoun-f: #fff3bf;
  --name-b:    #ffc81e;  --name-f:    #fff3bf;
  --verb-b:    #51cf66;  --verb-f:    #d3f9d8;
  --noun-b:    #ff922b;  --noun-f:    #ffe8cc;
  --describe-b:#4dabf7;  --describe-f:#d0ebff;
  --social-b:  #f783ac;  --social-f:  #ffdeeb;
  --question-b:#9775fa;  --question-f:#e5dbff;
  --negation-b:#ff6b6b;  --negation-f:#ffe3e3;
  --little-b:  #cdc1ac;  --little-f:  #f4efe4;
  --unknown-b: #d8cab2;  --unknown-f: #fbf6ec;

  --bar-h: clamp(50px, 7.2vh, 66px);
  --bar-fs: clamp(21px, 3.3vh, 30px);
  --chip-h: clamp(40px, 5.6vh, 52px);
  --chip-fs: clamp(17px, 2.6vh, 24px);

  --vvh: 100dvh;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  position: fixed;
  inset: 0;
  width: 100%;
  overscroll-behavior: none;
  background: var(--bg);
}

body {
  font-family: "Baloo 2", "Comic Sans MS", system-ui, sans-serif;
  color: var(--ink);
  user-select: none;
  -webkit-user-select: none;
}

/* warm paper with faint polka dots */
#app {
  position: fixed;
  top: 0; left: 0;
  width: 100%;
  height: var(--vvh);
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(var(--paper-dot) 1.6px, transparent 1.7px) 0 0 / 26px 26px,
    linear-gradient(180deg, #fffaf1 0%, var(--bg) 28%);
  will-change: transform;
}

/* ── top bar ─────────────────────────────────────────────────────────── */
#topbar {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 16px 4px;
}

#wordmark {
  font-weight: 800;
  font-size: clamp(20px, 3vh, 26px);
  letter-spacing: 0.5px;
  line-height: 1;
}
#wordmark span { display: inline-block; }
#wordmark span:nth-of-type(6n + 1) { color: #ff922b; transform: rotate(-4deg); }
#wordmark span:nth-of-type(6n + 2) { color: #51cf66; transform: rotate(3deg); }
#wordmark span:nth-of-type(6n + 3) { color: #4dabf7; transform: rotate(-2deg); }
#wordmark span:nth-of-type(6n + 4) { color: #f783ac; transform: rotate(4deg); }
#wordmark span:nth-of-type(6n + 5) { color: #9775fa; transform: rotate(-3deg); }
#wordmark span:nth-of-type(6n + 6) { color: #f5b301; transform: rotate(2deg); }

#topbar-right { display: flex; align-items: center; gap: 12px; }

#status-dot {
  width: 11px; height: 11px;
  border-radius: 50%;
  background: #ced4da;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.7);
}
#status-dot.ok   { background: #51cf66; }
#status-dot.warn { background: #ffc81e; }
#status-dot.off  { background: #ced4da; }

#gear {
  border: 0;
  background: none;
  color: var(--ink-soft);
  opacity: 0.55;
  padding: 8px;
  cursor: pointer;
}

/* ── history of spoken lines ─────────────────────────────────────────── */
#history {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  padding: 6px 0 14px;
  scrollbar-width: thin;
  scrollbar-color: #e8dcc4 transparent;
}

.line {
  flex: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  /* extra headroom so picture badges never get clipped by the row */
  padding: calc(var(--bar-h) * 0.32) 16px 8px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  border-radius: 22px;
}
.line::-webkit-scrollbar { display: none; }

#history .line { cursor: pointer; }
#history .line .bar { box-shadow: 0 2px 0 rgba(96, 70, 28, 0.06); }

/* ── word bars (the stickers) ────────────────────────────────────────── */
.bar {
  --b: var(--unknown-b);
  --f: var(--unknown-f);
  position: relative;
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 10px;
  height: var(--bar-h);
  padding: 0 0.62em;
  border-radius: 999px;
  border: 2.5px solid var(--b);
  background: var(--f);
  font-size: var(--bar-fs);
  font-weight: 700;
  line-height: 1;
  color: var(--ink);
  box-shadow: 0 3px 0 rgba(96, 70, 28, 0.08);
  transition: background 0.4s, border-color 0.4s;
  animation: pop 0.28s cubic-bezier(0.34, 1.56, 0.64, 1) both;
}
.line .bar:nth-child(3n)      { transform: rotate(0.7deg); }
.line .bar:nth-child(3n + 1)  { transform: rotate(-0.6deg); }
.line .bar:nth-child(3n + 2)  { transform: rotate(0.3deg); }

.pos-pronoun  { --b: var(--pronoun-b);  --f: var(--pronoun-f); }
.pos-name     { --b: var(--name-b);     --f: var(--name-f); }
.pos-verb     { --b: var(--verb-b);     --f: var(--verb-f); }
.pos-noun     { --b: var(--noun-b);     --f: var(--noun-f); }
.pos-describe { --b: var(--describe-b); --f: var(--describe-f); }
.pos-social   { --b: var(--social-b);   --f: var(--social-f); }
.pos-question { --b: var(--question-b); --f: var(--question-f); }
.pos-negation { --b: var(--negation-b); --f: var(--negation-f); }
.pos-little   { --b: var(--little-b);   --f: var(--little-f); }

/* picture = a little round badge peeking over the bar's top-right corner,
   ringed in the word's colour — the words themselves stay tightly packed */
.bar .pic {
  display: none;
  position: absolute;
  top: calc(var(--bar-h) * -0.18);
  right: calc(var(--bar-h) * -0.10);
  pointer-events: none;
}
.bar .pic img {
  display: block;
  width: calc(var(--bar-h) * 0.52);
  height: calc(var(--bar-h) * 0.52);
  border-radius: 50%;
  object-fit: cover;
  background: #fff;
  border: 2.5px solid var(--b);
  box-shadow: 0 2px 6px rgba(96, 70, 28, 0.2);
}
.bar .pic.ready { display: block; animation: pop 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) both; }

/* the in-progress word */
.bar.typing {
  background: #fff;
  border: 2.5px dashed #e3d5bd;
  box-shadow: none;
  min-width: 2.8em;
  color: var(--ink);
}
.bar.typing .ghosttxt { color: #c9b896; }
.bar.typing .hint { color: #d5c6a8; font-weight: 600; font-size: 0.85em; }

.caret {
  display: inline-block;
  width: 3px;
  height: 1.05em;
  margin: 0 1px;
  border-radius: 2px;
  background: #ff922b;
  animation: blink 1.05s steps(1) infinite;
}

/* ── the tray: current sentence + suggestions, sits above the keyboard ── */
#tray {
  flex: none;
  background: var(--card);
  border-top: 2px solid var(--edge);
  border-radius: 26px 26px 0 0;
  box-shadow: 0 -10px 30px rgba(124, 94, 42, 0.10);
  padding-bottom: max(env(safe-area-inset-bottom, 0px), 8px);
}

#current-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
#current-wrap::-webkit-scrollbar { display: none; }

#current-line {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: calc(var(--bar-h) * 0.32) 16px 8px;
  min-width: 100%;
}

#strip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 16px 12px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  min-height: calc(var(--chip-h) + 16px);
}
#strip::-webkit-scrollbar { display: none; }

.chip {
  --b: var(--unknown-b);
  --f: var(--unknown-f);
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: var(--chip-h);
  padding: 0 0.9em;
  border-radius: 999px;
  border: 2px solid var(--b);
  background: var(--f);
  font-family: inherit;
  font-size: var(--chip-fs);
  font-weight: 700;
  color: var(--ink);
  box-shadow: 0 2px 0 rgba(96, 70, 28, 0.07);
  cursor: pointer;
  animation: pop 0.22s ease-out both;
}
.chip:active, .bar:active, #history .line:active { transform: scale(0.96); }
.chip .done { color: var(--ink-soft); font-weight: 600; }

/* ── speaking feedback ───────────────────────────────────────────────── */
.line.speaking {
  background: linear-gradient(90deg, rgba(255, 243, 191, 0.55), rgba(255, 243, 191, 0.2));
}
.line.speaking .bar {
  animation: bounce 0.55s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  animation-delay: var(--d, 0s);
}

/* ── welcome card ────────────────────────────────────────────────────── */
#welcome {
  margin: auto;
  text-align: center;
  max-width: 30ch;
  padding: 26px 30px;
  background: #fffdf7;
  border: 2.5px solid var(--edge);
  border-radius: 26px;
  box-shadow: 0 4px 0 rgba(96, 70, 28, 0.06);
  transform: rotate(-0.5deg);
}
#welcome .wave { font-size: 44px; display: block; margin-bottom: 6px; }
#welcome h1 { margin: 0 0 6px; font-size: 26px; font-weight: 800; }
#welcome p { margin: 0; font-size: 18px; font-weight: 600; color: var(--ink-soft); line-height: 1.45; }

/* ── hidden real input (brings up the native keyboard) ───────────────── */
#ghost {
  position: fixed;
  left: 10px;
  bottom: 10px;
  width: 2px;
  height: 2px;
  padding: 0;
  border: 0;
  outline: 0;
  opacity: 0.01;
  font-size: 16px; /* stops iOS zooming on focus */
  background: transparent;
  color: transparent;
  caret-color: transparent;
  pointer-events: none;
}

/* ── toast + delete bubble ───────────────────────────────────────────── */
#toast {
  position: fixed;
  left: 50%;
  bottom: 30%;
  transform: translateX(-50%);
  background: var(--ink);
  color: #fff7ec;
  font-weight: 700;
  font-size: 16px;
  padding: 10px 18px;
  border-radius: 999px;
  box-shadow: 0 6px 18px rgba(74, 53, 32, 0.3);
  z-index: 60;
  animation: pop 0.2s ease-out both;
}

.delete-bubble {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 10px;
  background: #fffdf7;
  border: 2.5px solid var(--edge);
  border-radius: 999px;
  padding: 8px;
  box-shadow: 0 10px 30px rgba(74, 53, 32, 0.25);
  z-index: 55;
  animation: pop 0.18s ease-out both;
}
.delete-bubble button {
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  border-radius: 999px;
  padding: 8px 18px;
  cursor: pointer;
  border: 2px solid var(--little-b);
  background: var(--little-f);
  color: var(--ink);
}
.delete-bubble button.danger {
  border-color: var(--negation-b);
  background: var(--negation-f);
}

/* ── grown-ups panel ─────────────────────────────────────────────────── */
#overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(67, 48, 26, 0.4);
  backdrop-filter: blur(5px);
  -webkit-backdrop-filter: blur(5px);
}
#overlay[hidden] { display: none; }

.sheet {
  width: 100%;
  max-width: 460px;
  max-height: 86vh;
  overflow-y: auto;
  background: #fffdf7;
  border-radius: 26px;
  padding: 22px;
  box-shadow: 0 24px 60px rgba(40, 26, 8, 0.35);
}
.sheet h2 { margin: 0 0 14px; font-size: 24px; font-weight: 800; }
.sheet .prow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1.5px solid var(--edge);
  font-size: 17px;
  font-weight: 600;
}
.sheet .prow:last-of-type { border-bottom: 0; }
.sheet label { flex: 1; }
.sheet select, .sheet input[type="text"], .sheet input[type="password"] {
  font-family: inherit;
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  background: #fff;
  border: 2px solid var(--edge);
  border-radius: 14px;
  padding: 9px 12px;
  max-width: 56%;
}
.sheet input[type="checkbox"] { width: 24px; height: 24px; accent-color: #51cf66; }
.sheet .btn {
  font-family: inherit;
  font-size: 17px;
  font-weight: 700;
  border-radius: 999px;
  padding: 10px 20px;
  cursor: pointer;
  border: 2.5px solid var(--describe-b);
  background: var(--describe-f);
  color: var(--ink);
}
.sheet .btn.danger { border-color: var(--negation-b); background: var(--negation-f); }
.sheet .btn.primary { border-color: var(--verb-b); background: var(--verb-f); }
.sheet .statusline { display: flex; align-items: center; gap: 8px; font-size: 15px; }
.sheet .dot { width: 10px; height: 10px; border-radius: 50%; background: #ced4da; flex: none; }
.sheet .dot.on { background: #51cf66; }
.sheet .note { font-size: 14px; font-weight: 500; color: var(--ink-soft); margin: 10px 0 0; line-height: 1.4; }
.sheet .sheet-actions { display: flex; justify-content: space-between; gap: 10px; margin-top: 16px; }

/* unlock screen */
.sheet.unlock { text-align: center; }
.sheet.unlock input { max-width: 100%; width: 100%; text-align: center; font-size: 22px; margin: 12px 0; }

/* ── animations ──────────────────────────────────────────────────────── */
@keyframes pop {
  from { transform: scale(0.6); opacity: 0; }
  to   { transform: scale(1); opacity: 1; }
}
@keyframes blink { 50% { opacity: 0; } }
@keyframes bounce {
  0%   { transform: translateY(0); }
  35%  { transform: translateY(-14%) scale(1.05); }
  70%  { transform: translateY(2%) scale(1); }
  100% { transform: translateY(0); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-7px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-4px); }
}
.shake { animation: shake 0.3s ease-in-out; }

@keyframes arrive {
  from { transform: translateY(14px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}
.line.arrive { animation: arrive 0.3s ease-out; }

@keyframes fadeout {
  to { opacity: 0; transform: scale(0.92); }
}
.line.removing { animation: fadeout 0.25s ease-in both; }

@media (prefers-reduced-motion: reduce) {
  .bar, .chip, .line.arrive, .line.speaking .bar { animation: none !important; }
}

/* tighter top bar when the screen is short (phone landscape) */
@media (max-height: 460px) {
  #topbar { padding-top: 4px; }
  #wordmark { font-size: 18px; }
  #welcome { padding: 14px 22px; }
  #welcome .wave { font-size: 28px; }
}
