/* gotalk: hand-drawn look taken from the logo. Ink outlines, mint offset shadows, paper. */

:root {
  --paper: #f5f5f3;
  --surface: #ffffff;
  --ink: #1d1d1b;
  --text: #1d1d1b;
  --muted: #62625e;
  --line: #d9d9d4;
  --mint: #9cd5c3;
  --mint-soft: #e2f3ed;
  --mint-ink: #1f6f5c; /* mint dark enough for text */
  --me: #ededea;
  --danger: #c0392b;
  --ok: #2f9a78;
  --warn: #c98a1b;
  --stage: #121412;
  --art-filter: none;
  --radius: 18px;
  /* slightly uneven corners, like a marker drawing */
  --sketch: 22px 16px 24px 14px / 14px 24px 16px 22px;
  --sketch-sm: 14px 10px 15px 9px / 9px 15px 10px 14px;
  --font: "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --hand: "Caveat", "Segoe Print", "Bradley Hand", cursive;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper: #151816;
    --surface: #1d211f;
    --ink: #e6ebe8;
    --text: #e6ebe8;
    --muted: #a3aba7;
    --line: #333a36;
    --mint: #2f7a66;
    --mint-soft: #1f3a33;
    --mint-ink: #8fd6c1;
    --me: #262b28;
    --danger: #f07564;
    --ok: #5cc9a2;
    --warn: #e7b04f;
    /* inverts the drawings: ink lines turn light, mint turns deep teal */
    --art-filter: invert(1) hue-rotate(180deg) brightness(0.95);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--text);
  font: 16px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
}

main {
  max-width: 1080px;
  margin: 0 auto;
  padding: 20px 16px 32px;
  min-height: 100%;
}

[hidden] { display: none !important; }

/* Avoid a flash of English while the locale file loads. If the script never
   clears the class (e.g. it failed to load), show the page anyway after 2 s. */
.i18n-loading main { visibility: hidden; animation: reveal 0s 2s forwards; }
@keyframes reveal { to { visibility: visible; } }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip-path: inset(50%); white-space: nowrap;
}

h1, h2 { margin: 0; line-height: 1.15; }
h2 { font-family: var(--hand); font-weight: 700; font-size: 2.3rem; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.center { text-align: center; }
.art { filter: var(--art-filter); }

.card {
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--sketch);
  box-shadow: 6px 6px 0 var(--mint);
  padding: 22px;
}

/* ------------------------------------------------------------------ controls */

select, input[type="text"] {
  width: 100%;
  font: inherit;
  color: inherit;
  background: var(--paper);
  border: 1.5px solid var(--ink);
  border-radius: var(--sketch-sm);
  padding: 10px 12px;
}
input::placeholder { color: var(--muted); opacity: 1; }
select:focus-visible, input:focus-visible, button:focus-visible {
  outline: 3px solid var(--mint);
  outline-offset: 2px;
}

button {
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  color: var(--ink);
  background: var(--surface);
  border: 2px solid var(--ink);
  border-radius: var(--sketch-sm);
  padding: 9px 18px;
  box-shadow: 3px 3px 0 var(--mint);
  transition: transform 80ms ease, box-shadow 80ms ease;
}
button:hover:not(:disabled) { transform: translate(-1px, -1px); box-shadow: 4px 4px 0 var(--mint); }
button:active:not(:disabled) { transform: translate(2px, 2px); box-shadow: 1px 1px 0 var(--mint); }
button:disabled { opacity: 0.5; cursor: default; }

.primary { background: var(--mint); box-shadow: 3px 3px 0 var(--ink); }
.primary:hover:not(:disabled) { box-shadow: 4px 4px 0 var(--ink); }
.primary:active:not(:disabled) { box-shadow: 1px 1px 0 var(--ink); }
.danger { color: var(--danger); border-color: var(--danger); box-shadow: 3px 3px 0 color-mix(in srgb, var(--danger) 30%, transparent); }
.icon-btn { padding: 8px 12px; font-size: 1.1rem; line-height: 1; }

.error { color: var(--danger); font-weight: 600; margin: 0; }
.hint { color: var(--muted); font-size: 0.85rem; margin: 0; }

/* ------------------------------------------------------------------ landing */

#landing {
  display: grid;
  grid-template-columns: minmax(0, 1.05fr) minmax(0, 1fr);
  grid-template-areas: "top top" "brand form";
  gap: 8px 40px;
  align-items: center;
}

.topbar { grid-area: top; display: flex; justify-content: flex-end; }
.ui-lang { display: inline-flex; align-items: center; gap: 6px; }
.ui-lang select { width: auto; padding: 5px 10px; font-size: 0.9rem; background: var(--surface); }
.globe { font-size: 1.1rem; }

.brand { grid-area: brand; text-align: center; }
.hero {
  display: block; width: 100%; height: auto;
  /* the drawing is cropped at the bottom and right: fade those edges out */
  -webkit-mask-image: linear-gradient(to bottom, #000 82%, transparent), linear-gradient(to left, transparent, #000 7%);
  -webkit-mask-composite: source-in;
  mask-image: linear-gradient(to bottom, #000 82%, transparent), linear-gradient(to left, transparent, #000 7%);
  mask-composite: intersect;
}
.tagline {
  font-family: var(--hand);
  font-size: clamp(1.5rem, 2.6vw, 1.9rem);
  line-height: 1.25;
  margin: 4px auto 0;
  max-width: 30ch;
}

#join-form { grid-area: form; display: grid; gap: 20px; }

.field { display: grid; gap: 6px; border: 0; padding: 0; margin: 0; min-width: 0; }
.field > span, .field > legend { font-weight: 800; font-size: 0.95rem; padding: 0; margin-bottom: 6px; }
.field small { font-weight: 400; color: var(--muted); }

.lang-row { display: grid; grid-template-columns: 1fr auto 1fr; gap: 10px; align-items: end; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.chip {
  font-weight: 600;
  font-size: 0.9rem;
  padding: 4px 12px;
  border-width: 1.5px;
  border-radius: 999px 900px 999px 950px;
  background: var(--paper);
  box-shadow: none;
}
.chip:hover:not(:disabled) { box-shadow: 2px 2px 0 var(--mint); }
.chip[aria-selected="true"] { background: var(--mint); box-shadow: 2px 2px 0 var(--ink); }

#start { font-size: 1.1rem; padding: 12px 18px; }

/* -------------------------------------------------------------------- queue */

#queue .card {
  display: grid; gap: 10px; justify-items: center;
  max-width: 640px; margin: 32px auto 0; padding: 32px 22px;
}
#queue p { margin: 0; }
.note { background: var(--mint-soft); border-radius: var(--sketch-sm); padding: 6px 14px; font-weight: 600; }

.bob {
  width: 132px; height: auto;
  transform-origin: 50% 90%;
  animation: bob 2.4s ease-in-out infinite;
}
@keyframes bob {
  0%, 100% { transform: translateY(0) rotate(-3deg); }
  50% { transform: translateY(-8px) rotate(3deg); }
}
@media (prefers-reduced-motion: reduce) { .bob { animation: none; } }

.meter-row { display: flex; align-items: center; gap: 8px; margin: 8px 0; }
.meter { width: 140px; height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.meter > * { display: block; height: 100%; width: 0; background: var(--ok); transition: width 80ms linear; }

.preview-wrap { display: grid; justify-items: center; gap: 4px; margin: 8px 0; }
#queue-preview {
  width: 240px; aspect-ratio: 4 / 3;
  border: 2px solid var(--ink); border-radius: var(--sketch-sm);
  box-shadow: 4px 4px 0 var(--mint);
  background: var(--stage);
}
#queue-preview:not([data-live]) { display: none; }

/* --------------------------------------------------------------------- call */

main:has(#call:not([hidden])) { max-width: 1320px; }

#call { display: flex; flex-direction: column; gap: 14px; height: calc(100dvh - 52px); }

.call-head { display: flex; align-items: center; gap: 14px; padding: 8px 18px; box-shadow: 4px 4px 0 var(--mint); }
.mini-logo { width: 52px; height: auto; flex-shrink: 0; }
.call-who { flex: 1; min-width: 0; }
.partner { font-weight: 800; font-size: 1.15rem; }
.badge {
  font-size: 0.75rem; font-weight: 700;
  background: var(--mint-soft); color: var(--mint-ink);
  border: 1.5px solid currentColor; border-radius: 999px;
  padding: 1px 9px; vertical-align: middle;
}

.status { font-size: 0.85rem; font-weight: 600; white-space: nowrap; }
.status::before { content: "●"; margin-inline-end: 6px; }
.status[data-state="connecting"]::before { color: var(--warn); }
.status[data-state="connected"]::before { color: var(--ok); }
.status[data-state="failed"]::before { color: var(--danger); }

.call-body {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  gap: 16px;
}

/* The video area stays dark in both themes, like a screen. */
.stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background: var(--stage);
  color: #f2f3f1;
  border: 2px solid var(--ink);
  border-radius: var(--sketch);
  box-shadow: 6px 6px 0 var(--mint);
}
#remote-video { width: 100%; height: 100%; object-fit: contain; display: block; }

.placeholder {
  position: absolute; inset: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
  background: #1b1e1c;
  color: #b8c0bc;
}
.avatar {
  width: 96px; height: 96px;
  display: grid; place-items: center;
  font-size: 2.6rem; font-weight: 800;
  background: #9cd5c3; color: #1d1d1b;
  border: 2px solid #f2f3f1;
  border-radius: 48% 52% 50% 50% / 52% 48% 52% 48%;
}

.pill {
  position: absolute; top: 12px; inset-inline-start: 12px;
  background: rgb(0 0 0 / 0.65); color: #fff;
  font-size: 0.8rem; font-weight: 600; border-radius: 999px; padding: 4px 10px;
}

.live-caption {
  position: absolute; left: 50%; bottom: 20px; transform: translateX(-50%);
  width: max-content; max-width: min(90%, 820px);
  text-align: center;
}
.live-caption span {
  background: rgb(0 0 0 / 0.74); color: #fff;
  font-size: clamp(1rem, 2.4vw, 1.45rem); font-weight: 600; line-height: 1.45;
  padding: 3px 10px; border-radius: 6px;
  -webkit-box-decoration-break: clone; box-decoration-break: clone;
}
.live-caption.partial span { color: #d9ddd9; }

.self {
  position: absolute; inset-inline-end: 12px; top: 12px;
  width: clamp(96px, 22%, 220px); aspect-ratio: 4 / 3;
  overflow: hidden;
  background: #1b1e1c;
  border: 2px solid #f2f3f1;
  border-radius: var(--sketch-sm);
  box-shadow: 3px 3px 0 #9cd5c3;
}
.self-view { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; }
.self .placeholder { font-size: 0.75rem; }

.side { display: flex; flex-direction: column; gap: 12px; min-height: 0; }

.captions {
  flex: 1; min-height: 0; overflow-y: auto;
  display: flex; flex-direction: column; gap: 10px;
  padding: 14px;
  box-shadow: 5px 5px 0 var(--mint);
}
.captions .empty { margin: auto; text-align: center; font-family: var(--hand); font-size: 1.45rem; line-height: 1.25; }

.line { max-width: 90%; padding: 7px 12px; border: 1.5px solid var(--ink); }
.line .text { font-size: 1.02rem; }
.line .source { font-size: 0.78rem; color: var(--muted); margin-top: 2px; }
.line.them {
  align-self: flex-start;
  background: var(--mint-soft);
  border-radius: 16px 16px 16px 4px;
}
.line.me {
  align-self: flex-end;
  background: var(--me);
  border-color: var(--line);
  border-radius: 16px 16px 4px 16px;
}
:root[dir="rtl"] .line.them { border-radius: 16px 16px 4px 16px; }
:root[dir="rtl"] .line.me { border-radius: 16px 16px 16px 4px; }
.line.me .text { font-size: 0.92rem; }
.line.partial .text { opacity: 0.6; }

.composer { display: flex; gap: 8px; }
.composer input { min-width: 0; background: var(--surface); }
.composer button { flex-shrink: 0; white-space: nowrap; }

.controls { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; padding-bottom: 4px; }
.controls button { display: inline-flex; align-items: center; gap: 8px; }
#mute[aria-pressed="true"], #camera[aria-pressed="true"] { color: var(--danger); border-color: var(--danger); }
.small-meter { width: 36px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--ink); color: var(--paper);
  font-weight: 600;
  padding: 10px 16px; max-width: calc(100% - 32px);
  border-radius: var(--sketch-sm);
  box-shadow: 4px 4px 0 var(--mint);
}

/* --------------------------------------------------------------- responsive */

@media (max-width: 900px) {
  #landing { grid-template-columns: 1fr; grid-template-areas: "top" "brand" "form"; }
  .brand { max-width: 520px; margin: 0 auto; }
  .call-body { grid-template-columns: 1fr; grid-template-rows: minmax(200px, 1.3fr) minmax(140px, 1fr); }
}

@media (max-width: 520px) {
  main { padding: 12px 12px 24px; }
  .card { padding: 18px; box-shadow: 4px 4px 0 var(--mint); }
  .lang-row { grid-template-columns: 1fr; }
  #swap { justify-self: center; rotate: 90deg; }
  .hero { margin: -4px -8px 0; width: calc(100% + 16px); }
  h2 { font-size: 2rem; }
  #call { height: calc(100dvh - 36px); gap: 10px; }
  .call-head { padding: 6px 12px; gap: 10px; }
  .mini-logo { width: 40px; }
  .stage { box-shadow: 4px 4px 0 var(--mint); }
  .controls button { flex: 1; padding: 10px 6px; justify-content: center; }
  .small-meter { display: none; }
  .toast { top: 16px; bottom: auto; }
}
