/* Word Board – AAC app shell. No animations, no transitions, high contrast. */
:root {
  /* Modified Fitzgerald key */
  --people: #FFE14D;      /* yellow */
  --verb: #7FD67F;        /* green  */
  --descriptor: #86BDFF;  /* blue   */
  --noun: #FFB057;        /* orange */
  --social: #FF9FD0;      /* pink   */
  --negation: #FF7B7B;    /* red    */
  --little: #FFFFFF;      /* little words (and, the): white */
  --folder: #F2F2F2;      /* folders: white with a tab */
  --key: #FFFFFF;
  --bg: #1b1b1b;
  --ink: #000000;
  --gap: clamp(4px, 0.8vmin, 8px);
  --bar-h: clamp(92px, 15vh, 150px);
  --nav-h: clamp(52px, 7.5vh, 72px);
}
* { box-sizing: border-box; animation: none !important; transition: none !important; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: #fff;
  font-family: -apple-system, "SF Pro Rounded", system-ui, "Helvetica Neue", Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}
body { position: fixed; inset: 0; overflow: hidden; }
button, [role="button"] {
  font: inherit; color: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
#app, #app * { -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
/* pictures inside buttons must never start a drag or catch the touch */
#app img { -webkit-user-drag: none; pointer-events: none; }
/* touch feedback: the app handles presses itself (see onTap), so mirror :active with .pressed */
.arrow.pressed { background: #fff; color: #000; }
.sword.pressed { border-color: #000; }
.sbtn.pressed { background: #000; color: #fff; }
.tab.pressed, .action.pressed, #gear.pressed { filter: brightness(0.75); }

#app {
  position: absolute; inset: 0;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  display: grid;
  grid-template-rows: var(--bar-h) var(--nav-h) 1fr;
  gap: var(--gap);
}

/* ---------- message bar ---------- */
#bar {
  display: grid;
  grid-template-columns: 1fr repeat(3, clamp(84px, 11vw, 130px));
  gap: var(--gap);
  padding: var(--gap) var(--gap) 0 var(--gap);
  min-height: 0;
}
#msg {
  background: #fff; color: var(--ink);
  border-radius: 14px; border: 4px solid #fff;
  padding: 6px 14px;
  display: flex; flex-wrap: wrap; align-content: center; align-items: center;
  column-gap: 0.35em; row-gap: 0;
  font-weight: 700;
  font-size: clamp(28px, 5.2vmin, 54px);
  line-height: 1.15;
  overflow-y: auto; overflow-x: hidden;
  cursor: pointer; min-width: 0;
}
#msg .tok { padding: 0 0.08em; border-radius: 6px; white-space: nowrap; }
#msg .tok.now { background: #FFE14D; outline: 3px solid #000; }
#msg .buf { text-decoration: underline; text-decoration-thickness: 4px; text-underline-offset: 6px; white-space: nowrap; }
#msg .caret { display: inline-block; width: 4px; height: 1em; background: #000; margin-left: 2px; vertical-align: -0.12em; }
#msg.empty::before { content: ""; }

.action {
  border: 4px solid #fff; border-radius: 14px;
  background: #2d2d2d; color: #fff;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 800; padding: 2px; min-width: 0;
}
.action .ico { font-size: clamp(26px, 4.5vmin, 44px); line-height: 1; }
.action .txt { font-size: clamp(16px, 2.6vmin, 26px); margin-top: 4px; }
.action.speak { background: #0b5; color: #000; border-color: #000; outline: 3px solid #fff; outline-offset: -1px; }
.action:active, .action.pressed { background: #fff; color: #000; }

/* ---------- nav ---------- */
#nav {
  display: grid;
  grid-template-columns: repeat(3, clamp(118px, 16vw, 190px)) 1fr clamp(48px, 6vw, 64px);
  gap: var(--gap);
  padding: 0 var(--gap);
  min-height: 0;
}
.tab {
  border: 4px solid #777; border-radius: 12px;
  background: #2d2d2d; color: #fff;
  display: flex; align-items: center; justify-content: center; gap: 8px;
  font-weight: 800; font-size: clamp(17px, 2.8vmin, 30px); padding: 0 4px; min-width: 0; gap: 6px; white-space: nowrap; overflow: hidden;
}
.tab .ico { font-size: 1.1em; }
.tab.on { background: #fff; color: #000; border-color: #fff; }
#page-title {
  display: flex; align-items: center; justify-content: center;
  font-size: clamp(22px, 3.6vmin, 34px); font-weight: 800; color: #fff;
  white-space: nowrap; overflow: hidden;
}
#gear {
  border: 0; background: transparent; color: #555;
  font-size: clamp(26px, 3.6vmin, 36px);
}

/* ---------- board ---------- */
#board { min-height: 0; padding: 0 var(--gap) var(--gap) var(--gap); }
.grid {
  height: 100%;
  display: grid; gap: var(--gap);
}
.cell {
  container-type: size;
  border-radius: 14px; min-width: 0; min-height: 0;
}
.cell.blank { border: 2px dashed #333; }
/* fewer words shown: masked (and empty) cells disappear completely, but keep their place in the grid */
.grid.masking .cell.blank { border-color: transparent; }
.cell.btn {
  border: 4px solid rgba(0,0,0,0.55);
  color: var(--ink); cursor: pointer; padding: 3px;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  font-weight: 800; overflow: hidden;
}
.cell.btn:active, .cell.btn.pressed { border-color: #fff; outline: 4px solid #fff; filter: brightness(0.85); }
/* default for unknown types; :where() keeps specificity at zero so colour classes win */
:where(.cell.btn) { background: #fff; }
.t-people { background: var(--people); }
.t-verb { background: var(--verb); }
.t-descriptor { background: var(--descriptor); }
.t-noun { background: var(--noun); }
.t-social { background: var(--social); }
.t-negation { background: var(--negation); }
.t-little { background: var(--little); }
/* folder: light card with a grey outline and a grey tab across the top-left, readable on the dark background */
.t-folder {
  background: linear-gradient(#9a9a9a, #9a9a9a) left top / 46% 14px no-repeat, var(--folder);
  border-color: #9a9a9a !important; border-radius: 4px 14px 14px 14px;
}
.t-key { background: var(--key); }
.t-pred { background: #d9d9d9; }

.cell .emo {
  line-height: 1; font-size: min(38cqh, 44cqw);
  font-family: "Apple Color Emoji", "Noto Color Emoji", "Segoe UI Emoji", sans-serif;
  margin-bottom: 2cqh;
}
.cell .lbl {
  /* --len = longest word in the label (min 4): long words shrink to fit */
  font-size: min(calc(150cqw / var(--len, 4)), 30cqh, 64px);
  line-height: 1.02; text-align: center; overflow-wrap: normal; word-break: keep-all;
  letter-spacing: 0.01em;
}
.cell.nopic .lbl { font-size: min(calc(165cqw / var(--len, 4)), 42cqh, 84px); }
.cell.key .lbl { font-size: min(62cqh, 62cqw); line-height: 1; }
.cell.space .lbl { font-size: min(40cqh, 20cqw); }
.cell.pred .lbl { font-size: min(calc(150cqw / var(--len, 4)), 44cqh, 60px); }

/* keyboard view: prediction row + 4 letter rows */
.kbd { height: 100%; display: grid; grid-template-rows: 0.85fr 4.15fr; gap: calc(var(--gap) * 2); }
.kbd .preds { display: grid; grid-template-columns: repeat(6, 1fr); gap: var(--gap); }
.kbd .keys { display: grid; grid-template-columns: repeat(7, 1fr); grid-template-rows: repeat(4, 1fr) 0.55fr; gap: var(--gap); }
.cell.punct .lbl { font-size: min(70cqh, 70cqw); }
.cell.pred.empty { border: 2px dashed #333; background: transparent; }

/* ---------- parent settings ---------- */
#settings {
  position: fixed; inset: 0; z-index: 10; background: #f4f4f4; color: #111;
  display: flex; flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  font-size: 18px;
}
#settings[hidden] { display: none; }
.set-head { display: flex; align-items: center; justify-content: space-between; padding: 12px 20px; background: #222; color: #fff; }
.set-head h1 { margin: 0; font-size: 24px; }
.set-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding: 10px 20px 40px; }
#settings section { background: #fff; border: 1px solid #ccc; border-radius: 12px; padding: 12px 16px; margin: 12px 0; }
#settings h2 { font-size: 20px; margin: 4px 0 10px; }
#settings .row { display: flex; align-items: center; gap: 12px; margin: 10px 0; flex-wrap: wrap; }
#settings .row select { font-size: 17px; padding: 6px; max-width: 100%; }
#settings .row input[type=range] { flex: 1 1 240px; }
#settings .chk input { width: 24px; height: 24px; }
#settings .val { font-variant-numeric: tabular-nums; color: #555; min-width: 3em; }
#settings .note { color: #444; font-size: 15px; margin: 6px 0; }
#settings code { background: #eee; padding: 0 4px; border-radius: 4px; }
#settings textarea { width: 100%; font: 13px ui-monospace, Menlo, monospace; }
.pbtn { font-size: 17px; padding: 10px 16px; border-radius: 10px; border: 2px solid #333; background: #fff; color: #111; cursor: pointer; }
.pbtn.primary { background: #0b5; border-color: #0b5; color: #000; font-weight: 700; }
.pbtn.warn { border-color: #b00; color: #b00; }
.pbtn.file { position: relative; overflow: hidden; }
.pbtn.file input { position: absolute; inset: 0; opacity: 0; }
.btns { gap: 10px; }
.vis-page h3 { font-size: 17px; margin: 14px 0 6px; }
.vis-grid { display: grid; gap: 4px; }
.vis-cell { font-size: 13px; min-height: 40px; border-radius: 6px; border: 2px solid #0003; display: flex; align-items: center; justify-content: center; text-align: center; padding: 2px; color: #000; }
.vis-cell.empty { border: 1px dashed #bbb; color: #999; font-size: 11px; background: #fafafa; }
.vis-cell.hid { background: #eee !important; color: #888; text-decoration: line-through; border-style: dashed; }
.problems { color: #b00; font-size: 15px; }
#log-out table { border-collapse: collapse; font-size: 14px; margin-top: 8px; }
#log-out td, #log-out th { border: 1px solid #ccc; padding: 3px 8px; text-align: left; }

/* photos on buttons */
.cell .pic { display: block; object-fit: cover; border-radius: 8px; aspect-ratio: 1 / 1; height: 40cqh; margin-bottom: 2cqh; background: #fff; }

/* ---------- stories ---------- */
.story-list { height: 100%; display: grid; grid-template-columns: repeat(3, 1fr); grid-auto-rows: calc((100% - var(--gap)) / 2); gap: var(--gap); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.t-story { background: #fff; border-color: #000 !important; }
.note-dark { color: #bbb; font-size: 22px; }
.story { height: 100%; display: grid; grid-template-columns: clamp(96px, 13vw, 150px) 1fr clamp(96px, 13vw, 150px); gap: var(--gap); }
.arrow {
  border: 4px solid #fff; border-radius: 16px; background: #2d2d2d; color: #fff;
  display: flex; align-items: center; justify-content: center; padding: 0;
}
.arrow svg { width: 80%; max-height: 50%; }
.arrow:active { background: #fff; color: #000; }
.arrow:disabled { border-color: #333; color: #3a3a3a; background: transparent; }
.spage {
  background: #fff; color: #000; border-radius: 16px; min-width: 0; min-height: 0;
  display: grid; grid-template-rows: minmax(0, 1fr) auto auto; padding: 12px 16px; gap: 10px;
}
.spic { display: flex; align-items: center; justify-content: center; min-height: 0; overflow: hidden; container-type: size; }
.spic img { max-width: 100%; max-height: 100%; object-fit: contain; border-radius: 10px; }
.spic .semo { font-size: min(26vmin, 220px); line-height: 1; font-family: "Apple Color Emoji", "Noto Color Emoji", sans-serif; }
/* a "scene": 2–6 emoji side by side; the main subject (.main) is drawn bigger */
.spic .scene { display: flex; align-items: center; justify-content: center; gap: 2cqw; max-width: 100%; }
.spic .scene .semo { font-size: min(calc(76cqw / (var(--n, 3) * 1.25)), 52cqh, 190px); }
.spic .scene .semo.main { font-size: min(calc(76cqw * 1.5 / (var(--n, 3) * 1.25)), 82cqh, 280px); }
.stext { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px 14px; }
.sword {
  border: 3px solid transparent; background: transparent; border-radius: 10px; padding: 0 6px;
  font-weight: 800; font-size: clamp(38px, 7.2vmin, 76px); line-height: 1.15; color: #000;
}
.sword:active { border-color: #000; }
.sword.now { background: #FFE14D; border-color: #000; }
.sbar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; }
.sbtn { border: 3px solid #000; border-radius: 12px; background: #eee; color: #000; font-weight: 800; font-size: clamp(18px, 2.8vmin, 26px); padding: 10px 14px; justify-self: start; }
.sbtn.read { justify-self: end; background: #0b5; font-size: clamp(24px, 4vmin, 38px); padding: 10px 26px; }
.sbtn:active { background: #000; color: #fff; }
.scount { font-size: clamp(18px, 2.8vmin, 26px); font-weight: 700; color: #333; }

/* ---------- parent editor extras ---------- */
.vis-cell { flex-direction: column; cursor: pointer; }
.vis-cell img { width: 34px; height: 34px; object-fit: cover; border-radius: 4px; }
.vis-cell .lv { font-size: 10px; opacity: 0.6; text-decoration: none; }
.edit-modes { gap: 18px !important; }
.edit-modes input { width: 22px; height: 22px; vertical-align: middle; }
.story-row { display: flex; align-items: center; gap: 12px; margin: 6px 0; flex-wrap: wrap; }
.story-row img { width: 56px; height: 56px; object-fit: cover; border-radius: 6px; }
.story-row .semo-sm { width: 56px; text-align: center; font-size: 34px; }
.story-row .story-txt { flex: 1 1 200px; }
#settings details summary { font-weight: 700; cursor: pointer; margin: 8px 0; }
