@layer reset, base, layout, components, responsive;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  body, h1, h2, h3, p, ol, ul { margin: 0; }
  button, input, select, textarea { font: inherit; }
  button, a, input, select, summary { -webkit-tap-highlight-color: transparent; }
  button, summary { cursor: pointer; }
  img { display: block; max-width: 100%; }
  [hidden] { display: none !important; }
}

@layer base {
  :root {
    color-scheme: light;
    --paper: #f5f3ec;
    --surface: #fffefa;
    --ink: #252c29;
    --muted: #62675e;
    --line: #dedfd5;
    --lime: #e0ef9c;
    --lavender: #e5def5;
    --peach: #f5d0bc;
    --green: #36563f;
    --radius: 1.25rem;
    font-family: "Avenir Next", Avenir, "Segoe UI", system-ui, sans-serif;
    font-size: 16px;
    line-height: 1.5;
    font-weight: 500;
    color: var(--ink);
    background: var(--paper);
  }
  body { min-width: 320px; }
  a { color: inherit; text-underline-offset: .22em; }
  h1, h2, h3 { line-height: 1.12; letter-spacing: -.035em; font-weight: 650; text-wrap: balance; }
  h1 { font-size: clamp(3rem, 6.2vw, 5.4rem); }
  h2 { font-size: clamp(1.3rem, 2.2vw, 1.65rem); }
  p { overflow-wrap: anywhere; }
  strong { font-weight: 650; }
  button { color: inherit; }
  button:disabled { cursor: not-allowed; opacity: .5; }
  :focus-visible { outline: 3px solid #62529e; outline-offset: 4px; }
  ::selection { color: var(--ink); background: var(--lime); }
  input, select {
    width: 100%; min-width: 0; min-height: 3rem; border: 1px solid #b6bcae;
    border-radius: .65rem; padding: .75rem .9rem; color: var(--ink);
    background: var(--surface); font-size: 1rem;
  }
  input::placeholder { color: #707469; font-weight: 500; }
  input:focus, select:focus { border-color: #62529e; }
  select { padding-right: 1.7rem; }
  label { display: block; font-size: .875rem; font-weight: 650; }
  summary { list-style: none; font-weight: 650; }
  summary::-webkit-details-marker { display: none; }
  summary::after { content: "+"; margin-left: auto; padding-left: 1rem; font-size: 1.4rem; line-height: 1; font-weight: 500; }
  details[open] > summary::after { content: "−"; }
  summary { display: flex; align-items: center; gap: .5rem; min-height: 2.75rem; }
  .muted { color: var(--muted); }
  .small { font-size: .8125rem; line-height: 1.6; font-weight: 500; }
  .eyebrow { font-size: .75rem; font-weight: 700; letter-spacing: .12em; line-height: 1.6; }
  .serif { font-family: "Iowan Old Style", "Palatino Linotype", Georgia, serif; font-style: italic; font-weight: 500; }
  .lead { font-size: 1.1rem; max-width: 32rem; color: #575f52; line-height: 1.65; }
  .text-link { font-size: .875rem; font-weight: 650; }
  .skip-link { position: fixed; top: -6rem; left: 1rem; z-index: 10; padding: .8rem 1.2rem; background: var(--ink); color: white; border-radius: .5rem; }
  .skip-link:focus { top: 1rem; }
}

@layer layout {
  .topbar, .page, .footer { width: min(100% - 5rem, 76rem); margin-inline: auto; }
  .topbar { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding-block: 1.7rem; border-bottom: 1px solid var(--line); }
  .topbar nav { display: flex; align-items: center; gap: 1.75rem; }
  .page { padding-block: 3rem; }
  .footer { display: flex; justify-content: space-between; gap: 1rem; padding-block: 1.25rem 2rem; font-size: .75rem; font-weight: 600; color: var(--muted); border-top: 1px solid var(--line); }
  .stack { display: flex; flex-direction: column; gap: 1.15rem; min-width: 0; }
  .wide-gap { gap: 1.75rem; }
  .landing { display: grid; grid-template-columns: 1.25fr .85fr; gap: clamp(2rem, 6vw, 6rem); align-items: center; padding: 1rem 0 2.25rem; }
  .intro { display: flex; flex-direction: column; gap: 1.3rem; min-width: 0; }
  .page-heading { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
  .page-heading .eyebrow { margin-bottom: .5rem; }
  .page-title { font-size: clamp(2.2rem, 4vw, 3.1rem); }
  .lobby-grid { display: grid; grid-template-columns: 1fr 1fr; align-items: start; gap: 1.75rem; }
  .game-grid { display: grid; grid-template-columns: minmax(0, 1fr) 20.5rem; gap: 1.75rem; align-items: start; }
  .game-main, .game-sidebar { min-width: 0; }
  .game-sidebar { gap: 1.25rem; }
  .panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: clamp(1.25rem, 2.5vw, 2rem); min-width: 0; }
  .section-heading { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-bottom: 1.25rem; }
  .section-heading h2 { font-size: 1.15rem; }
  .button-row, .field-pair { display: flex; align-items: end; gap: .8rem; }
  .field-pair > * { flex: 1; min-width: 0; }
  .field { display: flex; flex-direction: column; gap: .5rem; min-width: 0; }
  .turn-form, .chat-form { display: flex; align-items: end; gap: .75rem; }
  .turn-form > .field, .chat-form > .field { flex: 1; }
  .turn-form .button, .chat-form .button { flex-shrink: 0; }
  .inline-form { display: inline-flex; }
  .rules-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 2rem; padding-block: 1.75rem; }
  .rules-grid section { display: flex; flex-direction: column; gap: 1rem; }
}

@layer components {
  .brand { display: inline-flex; align-items: center; text-decoration: none; font-size: 1.8rem; font-weight: 750; letter-spacing: -.065em; line-height: 1; }
  .brand img { margin-right: .6rem; }
  .brand-dot { color: #55743f; }
  .connection { display: flex; align-items: center; gap: .45rem; font-size: .75rem; font-weight: 600; color: var(--muted); }
  .connection-dot { width: .45rem; height: .45rem; border-radius: 50%; background: #bd733d; }
  .connection-dot.connected { background: #557e45; box-shadow: 0 0 0 4px #e1e8d9; }
  .badge { display: inline-flex; align-items: center; width: fit-content; border-radius: 2rem; padding: .4rem .7rem; background: #eeefe7; color: #555d4a; font-size: .75rem; font-weight: 700; letter-spacing: .045em; line-height: 1.4; }
  .count { display: inline-flex; justify-content: center; align-items: center; min-width: 1.8rem; min-height: 1.8rem; padding-inline: .45rem; border: 1px solid var(--line); border-radius: 2rem; font-size: .75rem; font-weight: 600; }
  .button { display: inline-flex; justify-content: center; align-items: center; min-height: 3rem; gap: .5rem; padding: .75rem 1.15rem; border: 1px solid var(--ink); border-radius: .7rem; background: var(--ink); color: #fffefa; font-size: .9375rem; font-weight: 650; line-height: 1.3; transition: background .15s, transform .15s; }
  .button:not(:disabled):hover { background: #424c39; transform: translateY(-1px); }
  .button:not(:disabled):active { transform: translateY(0); }
  .button.secondary { background: transparent; color: var(--ink); border-color: #aab29e; }
  .button.secondary:not(:disabled):hover { background: #e9eddf; }
  .button.compact { min-height: 2.75rem; font-size: .8125rem; padding: .65rem 1rem; }
  .notice { border: 1px solid #cc8e7c; border-radius: .8rem; padding: 1rem 1.25rem; margin-bottom: 1.5rem; background: #fbeee7; color: #833b29; font-weight: 600; }
  .notice:empty { display: none; }
  .join-panel { display: flex; flex-direction: column; gap: 1.35rem; padding: clamp(1.5rem, 3.5vw, 2.75rem); box-shadow: 0 14px 35px -22px #30372b35; }
  .join-panel h2 { font-size: 1.95rem; }
  .join-panel .stack { gap: 1.1rem; }
  .join-panel .badge { background: var(--lime); color: #43512a; }
  .seat-count { text-align: center; color: var(--muted); font-size: .875rem; }
  .seat-count strong { color: var(--ink); font-size: 1rem; }
  .divider { border-top: 1px dashed var(--line); }
  .card-fan { position: relative; width: 100%; max-width: 30rem; height: 16rem; margin-block: .5rem -.4rem; }
  .paper { position: absolute; display: flex; flex-direction: column; justify-content: space-between; width: 11rem; height: 13rem; padding: 1.1rem; border: 1px solid #252c2925; border-radius: .8rem; box-shadow: 0 5px 6px #252c290a, 0 15px 25px -15px #252c2933; }
  .paper > span { font-size: .75rem; font-weight: 600; letter-spacing: -.01em; }
  .paper > span:first-child { font-weight: 700; font-size: .75rem; }
  .paper strong { font-family: "Iowan Old Style", Georgia, serif; font-size: 2.1rem; font-weight: 500; text-align: center; }
  .paper-one { background: var(--lavender); left: .6rem; top: 1.5rem; transform: rotate(-13deg); }
  .paper-two { background: #e7eacf; left: 8.1rem; top: .65rem; transform: rotate(2deg); }
  .paper-blank { background: var(--peach); left: 15.4rem; top: 1.6rem; transform: rotate(14deg); }
  .paper-blank strong { font-family: inherit; letter-spacing: .06em; }
  .facts { display: flex; flex-wrap: wrap; gap: .6rem 1.1rem; font-size: .75rem; font-weight: 650; color: #636b59; }
  .facts span + span::before { content: "/"; color: #929780; margin-right: 1.1rem; }
  .setup-panel { display: flex; flex-direction: column; gap: 1.25rem; background: #eef1e3; }
  .setup-panel > .stack > .button { margin-top: .25rem; }
  .lobby-note { padding: 1.15rem; background: #f4f3ee; border-radius: .8rem; margin-block: 1.4rem; font-size: .875rem; }
  .lobby-note p { margin-top: .4rem; color: var(--muted); }
  .roster { list-style: none; padding: 0; display: flex; flex-direction: column; gap: .5rem; }
  .seat { display: flex; align-items: center; gap: .7rem; padding: .55rem .3rem; border-radius: .65rem; min-width: 0; }
  .seat.current { background: #eef3d9; margin-inline: -.5rem; padding-inline: .8rem; }
  .avatar { display: flex; align-items: center; justify-content: center; width: 2.4rem; height: 2.4rem; flex-shrink: 0; border-radius: .8rem; background: #e8e7dc; font-size: .875rem; font-weight: 650; }
  .avatar-0 { background: #e2e8c8; }
  .avatar-1 { background: var(--lavender); }
  .avatar-2 { background: var(--peach); }
  .avatar-3 { background: #d7e7e4; }
  .seat-info { display: flex; flex-direction: column; flex: 1; min-width: 0; }
  .player-name { font-size: .875rem; font-weight: 650; overflow-wrap: anywhere; }
  .presence { width: .45rem; height: .45rem; flex-shrink: 0; border-radius: 50%; border: 1px solid #747c6a; }
  .presence.online { background: #607c4b; border-color: #607c4b; }
  .remove-seat { display: grid; place-items: center; width: 2rem; height: 2rem; border: 0; border-radius: .4rem; background: transparent; color: #6c7562; font-size: 1.25rem; }
  .remove-seat:hover { background: #f5e8df; color: #733c27; }
  #roster > p { margin-top: 1rem; }
  .private-card { border: 1px solid #c5c3b8; border-radius: var(--radius); background: #ecebdf; overflow: hidden; }
  .private-card > summary { position: relative; display: flex; flex-direction: column; align-items: start; gap: .55rem; padding: 1.5rem; min-height: 9rem; }
  .private-card > summary::after { position: absolute; right: 1.5rem; top: 1.15rem; }
  .peek-title { font-family: "Iowan Old Style", Georgia, serif; font-size: 1.8rem; font-weight: 500; letter-spacing: -.025em; }
  .card-face { background: var(--lime); text-align: center; padding: 1.75rem 1.5rem; border-top: 1px dashed #858e65; }
  .blank-face { background: var(--peach); }
  .card-word { font-family: "Iowan Old Style", Georgia, serif; font-size: clamp(2.1rem, 3vw, 3rem); line-height: 1.15; padding-block: 1.6rem; overflow-wrap: anywhere; }
  .turn-panel { padding: clamp(1.5rem, 3vw, 2.5rem); border: 1px solid #c8ceac; border-radius: var(--radius); background: var(--lime); display: flex; flex-direction: column; gap: 1rem; min-width: 0; }
  .turn-panel h2 { font-size: clamp(1.7rem, 3vw, 2.15rem); }
  .turn-panel > p:not(.eyebrow) { max-width: 39rem; }
  .turn-panel .turn-form { margin-top: .4rem; }
  .turn-panel.waiting { background: #e9eddf; border-color: #d1d6c6; }
  .turn-panel.quiet { background: #e6e4ee; border-color: #cfccd9; }
  .turn-panel.vote-panel { --muted: #554b68; background: var(--lavender); border-color: #cfc4e2; }
  .turn-panel.result-panel { background: var(--lime); }
  .thinking-lines { display: flex; gap: .55rem; padding-block: .8rem; }
  .thinking-lines span { width: 3rem; height: .35rem; border-radius: .3rem; background: #a2b18d; }
  .thinking-lines span:nth-child(2) { width: 2rem; background: #b9c4a8; }
  .thinking-lines span:nth-child(3) { width: 1rem; background: #cbd2c0; }
  .guess-details { margin-top: .3rem; border-top: 1px solid #a2b078; padding-top: .6rem; }
  .guess-details summary { font-size: .875rem; }
  .guess-details p { padding-block: .75rem; }
  .guess-details[open] { padding-bottom: .25rem; }
  .locked-message { padding: .9rem 1rem; background: #ffffff70; border: 1px solid #bdb1d0; border-radius: .65rem; font-weight: 600; }
  .event-note { border-left: 3px solid #a6b793; padding: .25rem 1rem; color: #546046; font-size: .875rem; }
  .empty-state { color: var(--muted); padding-block: .5rem; line-height: 1.65; }
  .clue-list { list-style: none; padding: 0; max-height: 24rem; overflow-y: auto; scrollbar-width: thin; }
  .clue-row { display: flex; align-items: baseline; gap: .75rem; padding: .9rem .25rem; border-bottom: 1px solid #e8e8df; }
  .clue-row:last-child { border: 0; padding-bottom: 0; }
  .clue-row:first-child { padding-top: 0; }
  .round-marker { min-width: 1.8rem; font-size: .75rem; font-weight: 600; color: var(--muted); }
  .clue-author { font-size: .875rem; color: var(--muted); overflow-wrap: anywhere; flex: 1; }
  .spoken-word { font-size: 1.0625rem; font-weight: 600; text-align: right; overflow-wrap: anywhere; max-width: 55%; }
  .chat-panel { padding-bottom: 1.5rem; }
  .chat-panel .section-heading { margin-bottom: .5rem; flex-wrap: wrap; }
  .chat-panel .badge { background: #edece5; }
  .messages { display: flex; flex-direction: column; gap: .75rem; margin-block: 1.3rem; max-height: 18rem; overflow-y: auto; scrollbar-width: thin; }
  .message { display: flex; flex-direction: column; gap: .25rem; align-items: start; min-width: 0; font-size: .875rem; }
  .message > strong { font-size: .75rem; color: var(--muted); font-weight: 650; }
  .message > span { display: block; padding: .6rem .9rem; background: #f0f1e9; border-radius: .1rem .7rem .7rem; white-space: pre-wrap; max-width: 100%; }
  .chat-form .field { gap: .4rem; }
  .chat-form label { font-size: .75rem; color: var(--muted); }
  .spectator-panel { border-color: #c5bdd7; background: #f6f3fb; }
  .spectator-panel .badge, .spectator-panel .message > span { background: #e9e1f4; color: #514566; }
  .read-only-talk { margin-top: 1.25rem; border-top: 1px solid #d4cedd; padding-top: .7rem; }
  .read-only-talk summary { font-size: .875rem; }
  .host-controls .button { width: 100%; font-size: .8125rem; border-style: dashed; color: var(--muted); }
  .result-label { font-size: .75rem; font-weight: 700; letter-spacing: .08em; margin-top: .8rem; }
  .result-word { font-family: "Iowan Old Style", Georgia, serif; font-size: clamp(2.5rem, 5vw, 4rem); line-height: 1.1; letter-spacing: -.025em; }
  .result-panel .inline-form { margin-top: .75rem; }
  .ballots { padding-block: 1rem; }
  .ballots ul { padding-top: .75rem; line-height: 1.9; font-size: .875rem; }
  .rules { margin-top: 3rem; background: transparent; padding-block: .9rem; }
  .rules > summary { font-size: .9375rem; }
  .rules h2 { font-size: 1rem; }
  .rules-grid p { font-size: .875rem; color: var(--muted); }
  .rules[open] > .small { border-top: 1px solid var(--line); padding-block: 1rem .4rem; }
}

@layer responsive {
  @media (min-width: 1500px) { .page { padding-block: 4rem; } }
  @media (max-width: 1000px) {
    .topbar, .page, .footer { width: calc(100% - 3rem); }
    .landing { grid-template-columns: 1.1fr 1fr; gap: 2.5rem; }
    .card-fan { height: 14rem; }
    .paper { width: 9rem; height: 11rem; padding: .9rem; }
    .paper-one { left: .5rem; }
    .paper-two { left: 6rem; }
    .paper-blank { left: 11.5rem; }
    .paper strong { font-size: 1.8rem; }
    .game-grid { grid-template-columns: minmax(0, 1fr) 17rem; gap: 1.25rem; }
    .game-sidebar .panel { padding: 1.25rem; }
    .turn-form { flex-wrap: wrap; }
    .turn-form > .field { flex-basis: 100%; }
    .rules-grid { gap: 1.25rem; }
  }
  @media (max-width: 760px) {
    .topbar, .page, .footer { width: calc(100% - 2rem); }
    .topbar { padding-block: 1.25rem; }
    .topbar nav { gap: 1rem; }
    .brand { font-size: 1.55rem; }
    .brand img { width: 32px; height: 32px; }
    .connection { font-size: .75rem; }
    .page { padding-block: 2rem; }
    .landing { grid-template-columns: 1fr; padding-block: 0; gap: 2rem; }
    .intro { gap: 1rem; }
    .intro h1 { font-size: clamp(3rem, 11vw, 4.5rem); }
    .intro .lead { max-width: 34rem; font-size: 1rem; }
    .card-fan { margin-inline: auto; max-width: 24rem; height: 13rem; }
    .paper-one { left: 1rem; top: 1.3rem; }
    .paper-two { left: 7rem; top: .5rem; }
    .paper-blank { left: 13rem; top: 1.2rem; }
    .facts { justify-content: center; gap: .5rem; }
    .facts span + span::before { margin-right: .5rem; }
    .join-panel { max-width: 36rem; width: 100%; margin-inline: auto; }
    .join-panel h2 { font-size: 1.65rem; }
    .lobby-grid { grid-template-columns: 1fr; gap: 1.25rem; }
    .game-grid { display: flex; flex-direction: column; gap: 1.25rem; }
    .game-sidebar { order: -1; width: 100%; }
    .game-sidebar .private-card { order: -1; }
    .game-sidebar > .panel .roster { display: grid; grid-template-columns: 1fr 1fr; gap: .1rem .75rem; }
    .game-sidebar > .panel { padding-block: 1rem; }
    .game-sidebar > .panel #roster > p { display: none; }
    .game-sidebar .section-heading { margin-bottom: .6rem; }
    .game-sidebar .seat-info > .small { font-size: .75rem; }
    .game-sidebar .seat { padding-block: .4rem; }
    .game-sidebar .avatar { width: 2rem; height: 2rem; }
    .game-sidebar > .host-controls { display: block; }
    .private-card > summary { min-height: 5rem; padding: 1rem 1.25rem; gap: .15rem; }
    .private-card > summary .small { display: none; }
    .private-card > summary .peek-title { font-size: 1.35rem; }
    .private-card > summary::after { top: 1.5rem; }
    .card-face { padding-block: 1.25rem; }
    .card-word { padding-block: 1rem; }
    .game-main { width: 100%; }
    .page-heading { align-items: start; flex-wrap: wrap; }
    .page-heading .badge { margin-top: .65rem; }
    .page-title { font-size: 2.15rem; }
    .turn-form { flex-wrap: nowrap; }
    .turn-form > .field { flex-basis: auto; }
    .rules { margin-top: 2rem; }
    .rules-grid { grid-template-columns: 1fr; gap: 1.75rem; }
    .footer { flex-direction: column; gap: .4rem; padding-top: 1rem; }
  }
  @media (max-width: 420px) {
    .topbar { gap: .5rem; flex-wrap: wrap; }
    .topbar nav { gap: .75rem; }
    .brand { font-size: 1.4rem; }
    .brand img { width: 28px; height: 28px; }
    .text-link { font-size: .75rem; }
    .intro h1 { font-size: 3rem; }
    .card-fan { transform: scale(.9); transform-origin: left center; width: 110%; margin-bottom: -.75rem; }
    .paper { width: 8.5rem; }
    .paper-two { left: 6.6rem; }
    .paper-blank { left: 12.1rem; }
    .paper > span { font-size: .75rem; }
    .page-heading .button { font-size: .75rem; }
    .turn-form, .chat-form { flex-wrap: wrap; }
    .turn-form > .field, .chat-form > .field { flex-basis: 100%; }
    .turn-form .button, .chat-form .button { width: 100%; }
    .button-row { flex-direction: column; align-items: stretch; }
    .button-row .button, .button-row form { width: 100%; }
    .field-pair { flex-direction: column; align-items: stretch; }
    .clue-row { gap: .5rem; }
    .spoken-word { font-size: 1rem; }
  }
  @media (max-width: 360px) {
    .card-fan { transform: scale(.8); width: 100%; height: 12rem; }
  }
  @media (prefers-reduced-motion: reduce) { *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; animation: none !important; } }
}
