/* Oyako — one stylesheet, no framework.
   Every colour is declared in :root first, then overridden for dark.
   Nothing is defined only inside a media query: an unknown state must still
   have a colour. */

:root {
  color-scheme: light dark;

  /* surfaces: input is recessed, ground sits between, card is raised.
     The order must read the same in light and dark. */
  --ground: #F7F4EE;   /* 247 */
  --card:   #FFFFFF;   /* 255 */
  --input:  #ECE7DE;   /* 236 */
  --hair:   rgba(60, 46, 28, 0.13);
  /* The outline that says "this is a control". Surfaces alone cannot reach the
     3:1 a boundary needs — an unselected segment sat at 1.08:1 against the
     sheet and read as background. Measured: 3.26 light / 3.37 dark. */
  --edge:   rgba(60, 46, 28, 0.55);

  --ink:       #1B1710;
  --ink-2:     #5C5344;
  /* ink-3 carries timestamps and hints — small text, so it has to clear 4.5:1
     against the ground *and* against the recessed input. Measured: 5.14 / 4.58.
     The lighter grey this started as was 3.53 and would not have been legible. */
  --ink-3:     #6F6659;

  /* one accent. `accent` is for text/lines, `accent-fill` is for painted
     surfaces with white on top and never changes between light and dark. */
  --accent:      #A2560A;
  --accent-fill: #A2560A;
  --on-accent:   #FFFFFF;
  --accent-weak: rgba(162, 86, 10, 0.10);

  --danger: #6B1414;

  --radius: 18px;
  --radius-s: 12px;
  --tap: 44px;

  --gap-row: 8px;
  --gap-group: 24px;
  --pad-edge: 18px;

  --shadow: 0 1px 2px rgba(40, 30, 14, 0.06), 0 8px 24px rgba(40, 30, 14, 0.05);

  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP",
          "Segoe UI", Roboto, system-ui, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --ground: #1A1815;
    --card:   #262320;
    --input:  #100F0D;
    --hair:   rgba(255, 246, 232, 0.12);
    --edge:   rgba(255, 246, 232, 0.38);
    --ink:    #F5F0E7;
    --ink-2:  #BDB4A6;
    --ink-3:  #948C80;
    --accent: #F2A950;
    --accent-weak: rgba(242, 169, 80, 0.14);
    --danger: #E8867E;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
  }
}

:root[data-theme="dark"] {
  --ground: #1A1815;
  --card:   #262320;
  --input:  #100F0D;
  --hair:   rgba(255, 246, 232, 0.12);
  --edge:   rgba(255, 246, 232, 0.38);
  --ink:    #F5F0E7;
  --ink-2:  #BDB4A6;
  --ink-3:  #948C80;
  --accent: #F2A950;
  --accent-weak: rgba(242, 169, 80, 0.14);
  --danger: #E8867E;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

/* `hidden` must win. Every rule below that sets `display` on a button would
   otherwise override it, and the element stays on screen while the code
   believes it is gone — which is exactly how the back arrow turned up on the
   list screen and the switched-off sticker button stayed visible. */
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
}

body {
  background: var(--ground);          /* explicit: never inherit the host page */
  color: var(--ink);
  font-family: var(--font);
  font-size: 17px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  overscroll-behavior-y: none;
}

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

.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px;
  clip-path: inset(50%); overflow: hidden; white-space: nowrap;
}

:focus-visible {
  outline: 2.5px solid var(--accent);
  outline-offset: 2px;
  border-radius: 6px;
}

/* --- screens -------------------------------------------------------------- */

.screen { display: flex; flex-direction: column; height: 100%; }
.screen[hidden] { display: none; }
.view { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.view[hidden] { display: none; }

/* --- top bar: the three slots never change size --------------------------- */

.bar {
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: center;
  gap: 8px;
  padding: max(6px, env(safe-area-inset-top)) var(--pad-edge) 6px;
  background: var(--ground);
  border-bottom: 1px solid var(--hair);
  position: sticky; top: 0; z-index: 5;
}
.bar-slot { display: flex; align-items: center; justify-content: center; width: var(--tap); height: var(--tap); }
.bar-title {
  margin: 0;
  font-size: 20px;
  font-weight: 650;
  letter-spacing: 0.01em;
  text-align: center;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mark {
  flex: none;                          /* or the flex parent squashes it to an oval */
  width: 13px; height: 13px; border-radius: 50%;
  /* accent, not accent-fill: the fill colour is fixed for white text to sit on
     and goes muddy against a black ground */
  background: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-weak);
}

.icon-btn {
  width: var(--tap); height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: transparent;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .12s ease;
}
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.icon-btn:hover { background: var(--accent-weak); }
.icon-btn:active { background: var(--accent-weak); }

/* --- status line ---------------------------------------------------------- */

.status {
  margin: 0;
  padding: 6px var(--pad-edge);
  font-size: 13px;
  color: var(--ink-2);
  background: var(--ground);
  text-align: center;
}
.status[hidden] { display: none; }
.status.warn { color: var(--danger); }
.status.warn::before { content: "! "; font-weight: 700; }

/* --- roster --------------------------------------------------------------- */

.roster { list-style: none; margin: 0; padding: 8px 0 var(--gap-group); overflow-y: auto; flex: 1; }

/* The whole row is the target — name, avatar, preview, the lot. */
.row-btn {
  display: grid;
  grid-template-columns: 52px 1fr auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 72px;
  padding: 10px var(--pad-edge);
  border: 0;
  background: transparent;
  text-align: start;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .12s ease;
}
.row-btn:hover { background: var(--accent-weak); }
.row-btn:active { background: var(--accent-weak); }

.avatar {
  width: 52px; height: 52px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: var(--card);
  border: 1px solid var(--hair);
  font-size: 24px;
  line-height: 1;
}
.avatar.group { background: var(--accent-weak); border-color: transparent; color: var(--accent); }
.avatar svg { width: 30px; height: 30px; fill: currentColor; }
/* a face fills the circle and is cropped by it */
.avatar img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; display: block; }
.avatar { overflow: hidden; }

.face-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }

/* Name on top, last line under it. They are spans, so they need to be told to
   stack — inline by default they run together into one sentence. */
.row-text { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.row-name { display: block; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-last { display: block; font-size: 15px; color: var(--ink-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-meta { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.row-time { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.badge {
  min-width: 24px; height: 24px; padding: 0 7px;
  border-radius: 12px;
  background: var(--accent-fill); color: var(--on-accent);
  font-size: 13px; font-weight: 700; line-height: 24px; text-align: center;
  font-variant-numeric: tabular-nums;
}

/* --- being asked where you are -------------------------------------------- */

/* Plain accent, not a warning colour: the answer is optional and the screen
   must not say otherwise. */
.ask-bar {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; min-height: 54px;
  padding: 12px var(--pad-edge);
  border: 0; border-bottom: 1px solid var(--hair);
  background: var(--accent-weak); color: var(--accent);
  font-size: 17px; font-weight: 650; cursor: pointer;
  flex: none;
}
.ask-bar:hover { filter: brightness(0.97); }
.ask-bar .line { color: var(--accent); }

.ask-note {
  align-self: center;
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  margin: var(--gap-row) 0;
  padding: 8px 16px;
  max-width: 88%;
  border-radius: var(--radius);
  background: var(--card);
  color: var(--ink-2);
  font-size: 14px;
  text-align: center;
}
.ask-status { color: var(--ink-3); font-size: 13px; }

/* --- the trail (where they have been) ------------------------------------- */

.trail { list-style: none; margin: 0; padding: 8px 0 var(--gap-group); overflow-y: auto; flex: 1; }

/* The whole row opens the map — the "open in maps" words are a label, not the
   only target. */
.trail-row {
  display: grid;
  grid-template-columns: 28px 1fr auto;
  align-items: center;
  gap: 14px;
  width: 100%;
  min-height: 64px;
  padding: 12px var(--pad-edge);
  border: 0;
  background: transparent;
  text-align: start;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  transition: background-color .12s ease;
}
.trail-row:hover { background: var(--accent-weak); }
.trail-row:active { background: var(--accent-weak); }
.trail-row .line { width: 24px; height: 24px; }
.trail-text { min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.trail-who { font-size: 17px; font-weight: 600; }
.trail-when { font-size: 15px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
.trail-acc { font-size: 13px; color: var(--ink-3); font-variant-numeric: tabular-nums; }

.empty { padding: var(--gap-group) var(--pad-edge); color: var(--ink-2); text-align: center; }
.empty small { color: var(--ink-3); }

/* --- conversation --------------------------------------------------------- */

.stream {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  overflow-anchor: none;
  padding: var(--gap-group) var(--pad-edge) 10px;
  display: flex; flex-direction: column; gap: var(--gap-row);
  scroll-behavior: smooth;
}

.day {
  align-self: center;
  margin: var(--gap-group) 0 var(--gap-row);
  padding: 3px 12px;
  font-size: 13px; color: var(--ink-2);
  background: var(--accent-weak);
  border-radius: 999px;
}

.msg { display: flex; flex-direction: column; max-width: min(78%, 34rem); }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.msg.theirs { align-self: flex-start; }
.msg + .msg.same { margin-top: -4px; }

.who { font-size: 13px; color: var(--ink-3); margin: 0 6px 2px; }

.bubble-wrap { display: flex; align-items: flex-end; gap: 6px; }
.msg.mine .bubble-wrap { flex-direction: row-reverse; }

.bubble {
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--card);
  box-shadow: var(--shadow);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  text-align: start;
  border: 0;
  font: inherit;
  cursor: default;
}
.msg.mine .bubble { background: var(--accent-fill); color: var(--on-accent); }
.msg.pending .bubble { opacity: .62; }
.msg.failed .bubble { background: var(--card); color: var(--ink); border: 1.5px solid var(--danger); }

.stamp { font-size: 56px; line-height: 1.1; padding: 2px 6px; background: none; box-shadow: none; }
.msg.mine .stamp { background: none; color: inherit; }

.photo { display: block; max-width: 100%; border-radius: var(--radius); box-shadow: var(--shadow); }

/* The location card is one button: anywhere on it opens the map app. */
.place-card {
  display: flex; flex-direction: column; gap: 2px;
  min-height: var(--tap);
  padding: 12px 16px;
  cursor: pointer;
  transition: filter .12s ease;
}
.place-card b { font-weight: 650; }
.place-card:hover { filter: brightness(0.97); }
.msg.mine .place-card:hover { filter: brightness(1.08); }
.place-line { font-size: 14px; color: var(--ink-2); font-variant-numeric: tabular-nums; }
/* 0.88 white, not 0.8: on the amber fill the dimmer value measured 4.0:1 and
   this is 14px text. Measured now: 4.60. */
.msg.mine .place-line { color: rgba(255, 255, 255, 0.88); }
.place-open {
  margin-top: 4px;
  font-size: 14px; font-weight: 600;
  color: var(--accent);
}
.msg.mine .place-open { color: var(--on-accent); text-decoration: underline; }
.place-open::after { content: " ›"; }

.meta {
  display: flex; gap: 6px; align-items: center;
  font-size: 12px; color: var(--ink-3);
  margin: 2px 8px 0;
  font-variant-numeric: tabular-nums;
}
.meta .read { color: var(--accent); font-weight: 600; }
.meta .fail { color: var(--danger); font-weight: 600; }

/* the "…" is the same menu as right-click — so it is never the only way in.
   The glyph stays small; the target is 44px, because a 32px target on a phone
   is a miss. */
.dots {
  width: var(--tap); height: var(--tap);
  flex: none;
  border: 0; border-radius: 50%;
  background: transparent; color: var(--ink-3);
  font-size: 17px; line-height: 1;
  opacity: 0; cursor: pointer;
  transition: opacity .12s ease, background-color .12s ease;
}
.msg:hover .dots, .dots:focus-visible { opacity: 1; }
.dots:hover { background: var(--accent-weak); }

.retry {
  align-self: flex-end;
  margin: 2px 4px 0;
  padding: 6px 14px;
  min-height: 34px;
  border: 0; border-radius: 999px;
  background: var(--accent-weak); color: var(--accent);
  font-size: 14px; font-weight: 600; cursor: pointer;
}

.jump {
  position: absolute; left: 50%; transform: translateX(-50%);
  bottom: 96px; z-index: 4;
  padding: 9px 18px; min-height: var(--tap);
  border: 0; border-radius: 999px;
  background: var(--accent-fill); color: var(--on-accent);
  font-size: 15px; font-weight: 600; cursor: pointer;
  box-shadow: var(--shadow);
}
#view-room { position: relative; }

/* --- composer ------------------------------------------------------------- */

.composer {
  display: grid;
  grid-template-columns: var(--tap) 1fr var(--tap);
  align-items: end;
  gap: 8px;
  padding: 10px var(--pad-edge) max(10px, env(safe-area-inset-bottom));
  background: var(--ground);
  border-top: 1px solid var(--hair);
}
#input {
  width: 100%;
  min-height: var(--tap);
  max-height: 9rem;
  padding: 11px 16px;
  border: 1px solid var(--hair);
  border-radius: var(--radius);
  background: var(--input);
  resize: none;
}
#input:focus { outline-offset: 0; }

.send {
  width: var(--tap); height: var(--tap);
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: 50%;
  background: var(--accent-fill); color: var(--on-accent);
  cursor: pointer;
  transition: transform .1s ease, background-color .12s ease;
}
.send svg { width: 21px; height: 21px; fill: currentColor; }
.send:active { transform: scale(0.94); }
.send:disabled { background: var(--input); color: var(--ink-3); cursor: default; }

.plus svg { stroke-width: 2.1; }

/* The tray sits below the composer, so when it is open it is the thing that
   must clear the home bar — not the composer. */
.tray {
  display: flex; gap: 10px; flex-wrap: wrap;
  padding: 0 var(--pad-edge) max(12px, env(safe-area-inset-bottom));
  background: var(--ground);
}
.tray[hidden] { display: none; }
#view-room.tray-open .composer { padding-bottom: 10px; }
.stickers { max-height: 40vh; overflow-y: auto; }

.chip {
  display: inline-flex; align-items: center; gap: 8px;
  min-height: var(--tap); padding: 8px 16px;
  border: 0; border-radius: 999px;
  background: var(--accent-weak); color: var(--ink);
  font-size: 15px; font-weight: 600; cursor: pointer;
}
.chip.wide { width: 100%; justify-content: center; }
.chip:hover { background: var(--accent-weak); filter: brightness(0.97); }
/* the "not this one" button next to a CTA: no colour, so only one thing is amber */
.chip.quiet { background: transparent; border: 1px solid var(--edge); color: var(--ink); }
.chip.quiet:hover { background: var(--accent-weak); }
.chip svg.line, .line {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.8;
  stroke-linecap: round; stroke-linejoin: round;
  color: var(--accent);
}

.sticker-btn {
  width: 72px; height: 72px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; border-radius: var(--radius-s);
  background: transparent; font-size: 30px; cursor: pointer;
  padding: 6px;
}
/* The PNG is used as a mask and filled with the ink colour, so a drawing made
   with a black pen is still visible in dark mode. */
.sticker-art, .stamp-img {
  display: block;
  background-color: var(--ink);
  -webkit-mask: var(--art) center / contain no-repeat;
  mask: var(--art) center / contain no-repeat;
}
.sticker-art { width: 100%; height: 100%; }
.stamp-img { width: 132px; height: 132px; }
.msg.mine .stamp-img { background-color: var(--accent); }
.sticker-btn:hover { background: var(--accent-weak); }

.dropzone {
  position: absolute; inset: 0; z-index: 6;
  display: flex; align-items: center; justify-content: center;
  background: color-mix(in srgb, var(--ground) 88%, transparent);
  border: 2.5px dashed var(--accent);
  border-radius: var(--radius);
  color: var(--accent); font-weight: 650;
}
.dropzone[hidden] { display: none; }

/* --- panes (invite / gate) ------------------------------------------------ */

/* Top-aligned, not floating in the middle: the block used to sit with 304pt
   above it and 280pt below and nothing to anchor it. */
.pane { align-items: center; justify-content: flex-start; padding: var(--pad-edge); overflow-y: auto; }
.pane-inner { width: 100%; max-width: 26rem; margin-top: max(24px, 6vh); }
.pane-title { font-size: 34px; margin: 0 0 12px; letter-spacing: -0.01em; }
.pane-body { color: var(--ink-2); margin: 0 0 var(--gap-group); }

.brand { display: flex; flex-direction: column; align-items: flex-start; margin-bottom: var(--gap-group); }
.brand-mark { border-radius: 14px; display: block; }
.brand-name { font-size: 22px; font-weight: 700; margin-top: 10px; letter-spacing: 0.01em; }
.brand-tag { font-size: 15px; color: var(--ink-2); }

.field { display: block; margin-bottom: var(--gap-group); }
.field span { display: block; font-size: 15px; color: var(--ink-2); margin-bottom: 8px; }
.field input {
  width: 100%; min-height: var(--tap);
  padding: 10px 14px;
  border: 1px solid var(--hair); border-radius: var(--radius-s);
  background: var(--input);
}

.cta {
  min-height: var(--tap); padding: 12px 26px;
  border: 0; border-radius: 999px;
  background: var(--accent-fill); color: var(--on-accent);
  font-size: 17px; font-weight: 650; cursor: pointer;
}
.cta.wide { width: 100%; }
.cta:active { transform: scale(0.98); }

/* the one next step from the list, sitting in the space rather than in a menu */
.list-foot {
  padding: 0 var(--pad-edge) max(var(--gap-group), env(safe-area-inset-bottom));
  display: flex; justify-content: center;
}
.command {
  margin: 0 0 14px;
  padding: 12px 14px;
  border-radius: var(--radius-s);
  background: var(--input);
  border: 1px solid var(--hair);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 14px;
  overflow-x: auto;            /* the box scrolls, never the page */
  white-space: pre;
}

.error { color: var(--danger); font-weight: 600; }
.error[hidden] { display: none; }

/* --- settings sheet ------------------------------------------------------- */

.sheet {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  background: rgba(20, 15, 8, 0.42);
  padding: 0;
}
.sheet[hidden] { display: none; }
.sheet-card {
  width: 100%; max-width: 30rem;
  max-height: 88vh; overflow-y: auto;
  padding: var(--pad-edge) var(--pad-edge) max(var(--gap-group), env(safe-area-inset-bottom));
  background: var(--ground);
  border-radius: 24px 24px 0 0;
  box-shadow: var(--shadow);
}
.sheet-card.narrow { max-width: 24rem; border-radius: 24px; margin: auto; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 22px; margin: 0; }
.group { font-size: 13px; font-weight: 600; color: var(--ink-3); text-transform: none; margin: var(--gap-group) 0 8px; }

.segmented { display: flex; gap: 6px; flex-wrap: wrap; }
/* The unselected side needs an outline of its own. Recessed-surface colour
   alone left it indistinguishable from the sheet behind it. */
.segmented button {
  flex: 1 1 auto; min-height: var(--tap); padding: 8px 14px;
  border: 1px solid var(--edge); border-radius: var(--radius-s);
  background: transparent; color: var(--ink);
  font-size: 15px; cursor: pointer;
  transition: background-color .12s ease;
}
.segmented button:hover { background: var(--accent-weak); }
.segmented button[aria-checked="true"] {
  background: var(--accent-fill); border-color: var(--accent-fill);
  color: var(--on-accent); font-weight: 650;
}
.hint { font-size: 14px; color: var(--ink-3); margin: 8px 0 0; }
/* a note must not touch the control underneath it — it reads as a caption for
   the wrong thing */
.hint + .segmented { margin-top: 16px; }

.row { display: flex; gap: 10px; justify-content: flex-end; margin-top: var(--gap-group); }
#confirm-img { width: 100%; border-radius: var(--radius-s); margin-top: 12px; }

/* --- context menu --------------------------------------------------------- */

.menu {
  position: fixed; z-index: 30;
  min-width: 11rem; padding: 6px;
  background: var(--card); border: 1px solid var(--hair);
  border-radius: var(--radius-s); box-shadow: var(--shadow);
}
.menu[hidden] { display: none; }
.menu button {
  display: block; width: 100%; min-height: 40px;
  padding: 8px 12px; border: 0; border-radius: 8px;
  background: transparent; text-align: start; cursor: pointer;
}
.menu button:hover { background: var(--accent-weak); }

/* --- toast & sample note -------------------------------------------------- */

.toast {
  position: fixed; left: 50%; bottom: 84px; transform: translateX(-50%);
  z-index: 40; margin: 0;
  padding: 10px 18px; border-radius: 999px;
  background: var(--card); color: var(--ink);
  box-shadow: var(--shadow); font-size: 15px;
}
.toast[hidden] { display: none; }

/* A band under the bar, in the flow — not floating over the title.
   Same shape as .status so the two never fight for the same strip. */
.sample-note {
  margin: 0;
  padding: 6px var(--pad-edge);
  background: var(--accent-weak); color: var(--accent);
  font-size: 13px; font-weight: 600;
  text-align: center;
}
.sample-note[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  * { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}

@media (min-width: 820px) {
  :root { --pad-edge: 28px; }
  .bar, .status { max-width: 46rem; margin-inline: auto; width: 100%; }
  .roster, .stream, .composer, .tray { max-width: 46rem; margin-inline: auto; width: 100%; }
}
