/* GoobCloud: the phone app, drawn like the GoobCube's Word Processor.
   A slate desk; warm paper cards, sheets and fields with dark ink; a light
   top bar and tab bar; Courier Prime throughout (bold for titles); one blue
   accent; soft rounded corners and a gentle shadow. Each section keeps its
   Home tile colour only as a small mark (the active tab, the title's dot).
   The app is exactly one screen tall; only long lists scroll, inside .scroll. */

@font-face { font-family: "Courier Prime"; src: url("fonts/courier-prime.woff2") format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: "Courier Prime"; src: url("fonts/courier-prime-bold.woff2") format("woff2"); font-weight: 700; font-display: swap; }

:root {
  /* The Word Processor's colours (src/game_wordprocessor.py) */
  --desk: #282c36;        /* DESK */
  --desk-text: #c4cad6;   /* DESK_TEXT */
  --desk-muted: #848c9c;  /* DESK_MUTED */
  --paper: #fbf9f3;       /* PAPER */
  --paper-2: #f2efe7;     /* a step darker, for wells and thumbs */
  --ink: #222228;         /* INK */
  --ink-muted: #84848c;   /* BAR_MUTED */
  --bar: #f4f3ef;         /* BAR */
  --bar-line: #cecbc6;    /* BAR_LINE */
  --blue: #4074f0;        /* ACCENT */
  --blue-soft: #dee8ff;   /* ACCENT_SOFT */
  --red: #ce3e3e;         /* DANGER */
  --amber: #b9821e;
  --green: #2f9e5a;

  /* Names the screens use, mapped onto the paper look */
  --bg: var(--desk);
  --card: var(--paper);
  --panel: var(--paper-2);
  --text: var(--ink);
  --dim: var(--ink-muted);
  --faint: #a8a59e;
  --line: var(--bar-line);
  --divider: #e3dfd6;
  --lip: var(--bar-line);
  --white: #ffffff;
  --accent: #9ad0ff;      /* each section's Home tile colour, a small mark only */
  --on-accent: #ffffff;
  --notch: 0px;           /* the old notched corners, now square (radius gives the shape) */
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(0, 0, 0, .28), 0 4px 14px rgba(0, 0, 0, .16);
  --pixel: "Courier Prime", "Courier New", monospace;   /* (no more pixel font) */
  --mono: "Courier Prime", "Courier New", monospace;
  --bar-h: 56px;
  --tabs-h: 64px;
  color-scheme: light;
}

/* Sections: their Home tile colour, for the tab mark and the title's dot */
.sect-remote   { --accent: #4a9ee8; }
.sect-family   { --accent: #e86a90; }
.sect-words    { --accent: #e88a2a; }
.sect-music    { --accent: #d84cb6; }
.sect-games    { --accent: #8c56e0; }
.sect-settings { --accent: #7a8498; }

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
html { -webkit-text-size-adjust: 100%; }
body {
  background: var(--desk); color: var(--desk-text);
  font: 17px/1.4 var(--mono);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  overscroll-behavior: none;
}
@view-transition { navigation: auto; }
::view-transition-old(root), ::view-transition-new(root) { animation-duration: .12s; }

a { color: var(--blue); }
svg.px, img.px { display: block; shape-rendering: crispEdges; image-rendering: pixelated; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 3px solid var(--blue); outline-offset: 2px; }
[hidden] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Type (the old pixel sizes, now Courier Prime) ---------- */
.px-xs { font: 700 11px/1.1 var(--mono); letter-spacing: 0; }
.px-s  { font: 700 15px/1.2 var(--mono); }
.px-m  { font: 700 19px/1.2 var(--mono); }
.px-l  { font: 700 24px/1.15 var(--mono); }
.px-xl { font: 700 30px/1.1 var(--mono); }
.dim { color: var(--dim); }
.faint { color: var(--faint); }
.small { font-size: 14px; }

/* Paper things: rounded, a soft shadow on the desk */
.box, .item, .card, .setting, .note {
  border-radius: var(--radius); box-shadow: var(--shadow);
}
.box {
  background: var(--paper); color: var(--ink); border: 0;
  padding: 14px 16px;
}
.box.accent { box-shadow: inset 4px 0 0 var(--accent), var(--shadow); }
.box.panel { background: var(--paper-2); }

/* ---------- App frame: exactly one screen ---------- */
.app {
  height: 100dvh; display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  grid-template-columns: minmax(0, 1fr); /* a long title can't widen the app past the screen */
  max-width: 560px; margin: 0 auto;
  padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
  background: var(--desk); position: relative;
}
.app.wide { max-width: none; }
@media (min-width: 600px) {
  body { background: #1c1f27; }
  .app:not(.wide) { box-shadow: 0 0 0 1px #343946, 0 10px 40px rgba(0, 0, 0, .4); }
}

/* Top bar, like the Word Processor's: light, a hairline under it, bold title */
.bar {
  background: var(--bar); color: var(--ink); border-bottom: 1px solid var(--bar-line);
  padding: calc(env(safe-area-inset-top) + 8px) 8px 8px;
  display: flex; align-items: center; gap: 6px; min-height: var(--bar-h);
}
.chip {
  display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px;
  background: transparent; border: 0; border-radius: var(--radius-s); color: var(--ink);
  text-decoration: none; white-space: nowrap; min-width: 0; font-weight: 700;
}
button.chip { cursor: pointer; }
.chip:hover { background: rgba(0, 0, 0, .05); }
.chip:active { background: rgba(0, 0, 0, .09); }
.chip.title { flex: 1 1 auto; padding-left: 4px; overflow: hidden; gap: 10px; }
.chip.title:hover, .chip.title:active { background: transparent; }
.chip.title svg.px { width: 26px; height: 26px; padding: 3px; background: #fff; border-radius: 7px; box-shadow: inset 0 0 0 2px var(--accent); }
.chip.title .label { overflow: hidden; text-overflow: ellipsis; min-width: 0; font: 700 19px/1.2 var(--mono); }
.chip.icon-only { width: 44px; height: 40px; padding: 0; justify-content: center; }
.chip.accent { background: var(--blue); color: #fff; }
.chip.accent:hover { background: #3566dc; }
.status-dot { width: 10px; height: 10px; border-radius: 50%; background: var(--faint); flex: none; }
.status-dot.on { background: #34c35c; }
.status-dot.off { background: var(--red); }

/* The main area fits the screen; its children decide what scrolls */
.screen {
  min-height: 0; display: flex; flex-direction: column; gap: 12px;
  padding: 14px 14px 12px; overflow: hidden;
}
.screen.pad-0 { padding: 0; gap: 0; }
.scroll {
  flex: 1 1 auto; min-height: 0; overflow-y: auto; overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch; scrollbar-width: thin;
  margin: 0 -14px; padding: 2px 14px 14px;
}
.fill { flex: 1 1 auto; min-height: 0; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack.tight { gap: 8px; }
.row-wrap { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.spacer { flex: 1 1 auto; }

/* Bottom tabs: the light bar again */
.tabs {
  display: grid; grid-template-columns: repeat(5, minmax(0, 1fr));
  background: var(--bar); border-top: 1px solid var(--bar-line);
  padding: 6px 4px calc(env(safe-area-inset-bottom) + 6px);
}
.tab {
  display: flex; flex-direction: column; align-items: center; gap: 4px;
  padding: 6px 0 2px; text-decoration: none; color: var(--ink-muted); position: relative;
}
.tab .px-xs { color: inherit; font-weight: 400; font-size: 12px; white-space: nowrap; }
.tab svg.px { width: 26px; height: 26px; }
.tab[aria-current="page"] { color: var(--ink); }
.tab[aria-current="page"] .px-xs { font-weight: 700; }
.tab[aria-current="page"]::before { content: ""; position: absolute; top: -7px; left: 30%; right: 30%; height: 3px; border-radius: 0 0 3px 3px; background: var(--tab-color, var(--accent)); }
.tab:not([aria-current="page"]) svg.px { opacity: .55; filter: saturate(.6); }

/* ---------- Lists: paper cards on the desk ---------- */
.list { display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; list-style: none; }
.item {
  display: flex; align-items: center; gap: 12px; min-height: 64px; padding: 8px 14px 8px 8px;
  background: var(--paper); border: 0; color: var(--ink); text-decoration: none;
}
a.item:active, button.item:active { background: var(--blue-soft); }
button.item { width: 100%; text-align: left; cursor: pointer; }
.item .thumb { width: 48px; height: 48px; flex: none; background: var(--paper-2); object-fit: cover; border-radius: var(--radius-s); }
.item .main { flex: 1 1 auto; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.item .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .sub { color: var(--ink-muted); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chev { color: var(--faint); flex: none; }
.section-label { color: var(--desk-muted); margin: 8px 4px 0; font: 700 13px/1.2 var(--mono); }
.badge { display: inline-block; padding: 3px 8px; border-radius: 999px; background: var(--paper-2); color: var(--ink-muted); font: 700 11px/1.2 var(--mono); }
.badge.accent { background: var(--blue-soft); color: var(--blue); }

/* A grid of square cards (words, assets) */
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 10px; }
.card {
  display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 8px 10px;
  background: var(--paper); border: 0; color: var(--ink); text-decoration: none; min-width: 0;
}
.card img, .card .thumb { width: 100%; aspect-ratio: 1; object-fit: cover; background: var(--paper-2); border-radius: var(--radius-s); }
.card .name { font-weight: 700; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 48px; padding: 0 18px; cursor: pointer; text-decoration: none;
  background: var(--paper); color: var(--ink); border: 1px solid var(--bar-line); border-radius: var(--radius-s);
  font: 700 16px/1 var(--mono); box-shadow: 0 1px 1px rgba(0, 0, 0, .12);
}
.btn:active { filter: brightness(.95); }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.danger { color: var(--red); border-color: #e7b9b9; }
.btn.danger.solid { background: var(--red); border-color: var(--red); color: #fff; }
.btn.block { display: flex; width: 100%; }
.btn[disabled] { opacity: .45; cursor: default; }
.btn-row { display: flex; gap: 8px; }
.btn-row > * { flex: 1 1 0; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .field > .label { font: 700 13px/1.2 var(--mono); color: var(--ink-muted); }
.input, .field input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]), .field select, .field textarea {
  width: 100%; min-height: 48px; padding: 10px 12px; background: #fff; color: var(--ink);
  border: 1px solid var(--bar-line); border-radius: var(--radius-s); font-size: 17px; appearance: none; -webkit-appearance: none;
}
.field textarea { resize: none; }
.field select { background-image: linear-gradient(45deg, transparent 50%, var(--ink-muted) 50%), linear-gradient(-45deg, transparent 50%, var(--ink-muted) 50%);
  background-position: calc(100% - 20px) 50%, calc(100% - 14px) 50%; background-size: 6px 6px; background-repeat: no-repeat; padding-right: 36px; }
.input:focus, .field input:focus, .field select:focus, .field textarea:focus { border-color: var(--blue); box-shadow: 0 0 0 3px var(--blue-soft); outline: none; }
.hint { color: var(--ink-muted); font-size: 14px; }
.screen > .hint, .screen > .stack > .hint { color: var(--desk-muted); }

/* A settings-style row: label left, control right */
.setting { display: flex; align-items: center; gap: 12px; min-height: 60px; padding: 8px 14px; background: var(--paper); color: var(--ink); border: 0; }
.setting .main { flex: 1 1 auto; min-width: 0; }
.setting .name { font-weight: 700; }
.setting .sub { color: var(--ink-muted); font-size: 14px; }
.group { display: flex; flex-direction: column; gap: 6px; }

/* Switch: a rounded pill */
.switch { position: relative; flex: none; width: 52px; height: 32px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; }
.switch .track { position: absolute; inset: 0; pointer-events: none; background: #d9d5cc; border: 0; border-radius: 999px; transition: background .15s; }
.switch .knob { position: absolute; top: 3px; left: 3px; width: 26px; height: 26px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, .3); transition: transform .15s; }
.switch input:checked + .track { background: var(--blue); }
.switch input:checked + .track .knob { transform: translateX(20px); background: #fff; }
.switch input:focus-visible + .track { outline: 3px solid var(--blue-soft); outline-offset: 2px; }

/* Segmented control */
.seg { display: flex; padding: 3px; gap: 3px; border: 0; border-radius: 10px; background: var(--paper-2); }
.seg label { flex: 1 1 0; position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; }
.seg span { display: flex; align-items: center; justify-content: center; min-height: 38px; padding: 0 10px; border-radius: 8px; font: 700 15px/1 var(--mono); color: var(--ink-muted); }
.seg input:checked + span { background: #fff; color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, .18); }
.seg input:focus-visible + span { outline: 3px solid var(--blue-soft); outline-offset: -3px; }

/* Range slider */
input[type=range].px-range { -webkit-appearance: none; appearance: none; width: 100%; height: 32px; background: transparent; }
input[type=range].px-range::-webkit-slider-runnable-track { height: 6px; background: #ddd8ce; border: 0; border-radius: 3px; }
input[type=range].px-range::-webkit-slider-thumb { -webkit-appearance: none; width: 26px; height: 26px; margin-top: -10px; background: #fff; border: 0; border-radius: 50%; box-shadow: 0 1px 4px rgba(0, 0, 0, .35); }
input[type=range].px-range::-moz-range-track { height: 6px; background: #ddd8ce; border: 0; border-radius: 3px; }
input[type=range].px-range::-moz-range-progress { height: 6px; background: var(--blue); border-radius: 3px; }
input[type=range].px-range::-moz-range-thumb { width: 26px; height: 26px; background: #fff; border: 0; border-radius: 50%; box-shadow: 0 1px 4px rgba(0, 0, 0, .35); }

/* ---------- Sheets, toasts, empty states ---------- */
dialog.sheet {
  margin: auto auto 0; width: 100%; max-width: 560px; max-height: 88dvh; padding: 0;
  background: var(--paper); color: var(--ink); border: 0; border-radius: 16px 16px 0 0;
  box-shadow: 0 -8px 30px rgba(0, 0, 0, .35);
  display: none; flex-direction: column;
}
dialog.sheet[open] { display: flex; animation: sheet-in .2s ease-out; }
dialog.sheet::backdrop { background: rgba(16, 18, 24, .6); }
@keyframes sheet-in { from { transform: translateY(40px); opacity: .4; } }
.sheet-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 8px; }
.sheet-head::before { content: ""; position: absolute; left: 50%; top: 7px; width: 40px; height: 4px; margin-left: -20px; border-radius: 2px; background: #d9d5cc; }
.sheet-head h2 { margin: 0; flex: 1 1 auto; font: 700 20px/1.2 var(--mono); color: var(--ink); }
.sheet-body { padding: 4px 16px 16px; overflow-y: auto; overscroll-behavior: contain; display: flex; flex-direction: column; gap: 12px; }
.sheet-body .item, .sheet-body .setting, .sheet-body .card, .sheet-body .box { box-shadow: 0 0 0 1px var(--divider); }
.sheet-foot { padding: 4px 16px calc(env(safe-area-inset-bottom) + 16px); display: flex; flex-direction: column; gap: 8px; }
dialog.sheet.danger .sheet-head h2 { color: var(--red); }
dialog.sheet.full { height: 100dvh; max-height: 100dvh; border-radius: 0; }
dialog.sheet.full .sheet-head::before { display: none; }
dialog.sheet.full .sheet-head { padding-top: calc(env(safe-area-inset-top) + 12px); background: var(--bar); border-bottom: 1px solid var(--bar-line); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--tabs-h) + env(safe-area-inset-bottom) + 20px);
  transform: translate(-50%, 12px); opacity: 0; pointer-events: none; z-index: 20;
  padding: 11px 18px; background: #1d2028; border: 0; border-radius: 999px; color: #fff;
  font: 700 15px/1.2 var(--mono); box-shadow: 0 6px 20px rgba(0, 0, 0, .35);
  transition: opacity .15s, transform .15s; max-width: calc(100% - 32px);
}
.toast::before { content: "\2713  "; color: #6fdc8c; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error::before { content: "!  "; color: #ff8a80; }

.empty { flex: 1 1 auto; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; text-align: center; padding: 24px; color: var(--desk-muted); }
.empty .px-m { color: var(--desk-text); }

.note { padding: 10px 14px; border: 0; color: #6b4a10; background: #fbf0d6; font-size: 15px; }
.note.error { color: #8a2424; background: #fbe1e1; }

/* Screens without the tab bar (login, pairing) */
.app.bare { grid-template-rows: auto minmax(0, 1fr); }
.center-col { flex: 1 1 auto; display: flex; flex-direction: column; justify-content: center; gap: 16px; }

@media (prefers-reduced-motion: reduce) {
  dialog.sheet[open] { animation: none; }
  .toast, .switch .knob, .switch .track { transition: none; }
  ::view-transition-old(root), ::view-transition-new(root) { animation: none; }
}
