:root {
    --gold: #e4c56a;
    --ink: #f6f1e6;
    --dim: #b7c0b6;
    --bg: #101513;
  }
  * { box-sizing: border-box; }
  html, body { margin: 0; height: 100%; overflow: hidden; }
  body {
    height: 100%;
    color: var(--ink);
    font-family: "Segoe UI", sans-serif;
    background:
      radial-gradient(ellipse at 50% 0%, #24302a 0%, #101513 55%);
    display: flex;
    flex-direction: column;
    align-items: center;
    user-select: none;
  }
  body > header {
    width: min(1200px, calc(100% - 12px));
    flex: 0 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: max(4px, env(safe-area-inset-top)) 2px 0;
    padding-left: max(2px, env(safe-area-inset-left));
    padding-right: max(2px, env(safe-area-inset-right));
  }
  h1 {
    margin: 0;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 16px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: #f3e6c4;
  }
  .scoreboard {
    width: min(1200px, calc(100% - 12px));
    flex: 0 0 auto;
    display: grid;
    grid-template-columns: minmax(88px, 1fr) minmax(96px, 200px) minmax(88px, 1fr);
    gap: 6px;
    align-items: center;
  }
  body:not(.playing) .scoreboard,
  body:not(.playing) #table-wrap { display: none; }
  .player {
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.08);
    border-radius: 12px;
    padding: 4px 8px;
    min-width: 0;
  }
  .player.active {
    border-color: rgba(228,197,106,0.9);
    background: rgba(228,197,106,0.07);
    box-shadow: 0 0 0 1px rgba(228,197,106,0.25);
  }
  .player header {
    width: auto;
    padding: 0;
    display: flex;
    justify-content: space-between;
    align-items: center;
  }
  button.who {
    background: none;
    border: none;
    border-radius: 0;
    padding: 0;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-size: 14px;
    font-weight: 650;
    color: inherit;
    text-align: left;
  }
  button.who:not(:disabled) {
    cursor: pointer;
    text-decoration: underline;
    text-decoration-color: rgba(228,197,106,0.45);
    text-underline-offset: 3px;
  }
  button.who:disabled { cursor: default; opacity: 1; }
  .clock {
    margin: 2px 0 0;
    min-height: 16px;
    color: var(--gold);
    font-size: 13px;
    font-variant-numeric: tabular-nums;
  }
  .badge {
    color: var(--gold);
    font-size: 11px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    min-height: 14px;
  }
  .group { margin: 0; color: var(--dim); font-size: 12px; min-height: 16px; }
  .clock:empty { display: none; }
  .left { color: var(--gold); font-size: 12px; min-height: 16px; }
  .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 2px; min-height: 22px; }
  .chip {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background:
      radial-gradient(circle at 50% 50%, #fff 0 6px, transparent 7px),
      radial-gradient(circle at 35% 30%, #fff, var(--c) 42%, #111 100%);
    color: #161616;
    font-size: 9px;
    font-weight: 800;
  }
  .chip.stripe {
    background:
      radial-gradient(circle at 50% 50%, #fff 0 6px, transparent 7px),
      linear-gradient(#f4f4f4 0 24%, var(--c) 25% 75%, #f4f4f4 76%);
  }
  .empty { color: rgba(255,255,255,0.25); }
  .mid {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    text-align: center;
    padding: 0 4px;
    min-width: 0;
  }
  .eight {
    width: 22px;
    height: 22px;
    border-radius: 50%;
    display: grid;
    place-items: center;
    font-size: 11px;
    font-weight: 800;
    background: radial-gradient(circle at 35% 30%, #666, #111 62%);
    border: 2px solid transparent;
  }
  .eight.hot {
    border-color: var(--gold);
    box-shadow: 0 0 14px rgba(228,197,106,0.65);
  }
  #status {
    margin: 0;
    height: 2.6em;
    font-size: 12px;
    line-height: 1.3;
    max-width: 100%;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }
  .open-row { display: flex; gap: 4px; justify-content: center; min-height: 22px; }
  .power {
    width: 100%;
    height: 8px;
    border-radius: 99px;
    background: #1b2420;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.06);
  }
  .power > div {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #e4c56a, #ff5a36);
  }
  #table-wrap {
    flex: 1 1 auto;
    min-height: 0;
    width: min(1200px, calc(100% - 8px));
    margin: 2px 0 max(4px, env(safe-area-inset-bottom));
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 0;
    filter: drop-shadow(0 16px 22px rgba(0,0,0,0.45));
  }
  #wait-screen {
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    color: var(--dim);
    font-size: 18px;
  }
  body:not(.waiting) #wait-screen { display: none; }
  #home {
    display: none;
    flex: 1 1 auto;
    align-items: center;
    justify-content: center;
    padding: 16px;
  }
  body.home #home { display: flex; }
  .home-mark { text-align: center; width: min(340px, 86vw); }
  .welcome {
    margin: 0 0 12px;
    color: #f3e6c4;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 22px;
  }
  .welcome:empty { display: none; }
  .home-mark svg {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 18px 24px rgba(0,0,0,0.45));
  }
  .home-mark h2 {
    margin: 14px 0 4px;
    font-family: Georgia, "Times New Roman", serif;
    font-weight: 600;
    letter-spacing: 0.16em;
    text-transform: uppercase;
    color: #f3e6c4;
  }
  .home-mark p { margin: 0; color: var(--dim); font-size: 14px; }
  .rules-card { text-align: left; width: min(520px, calc(100% - 24px)); }
  .rules-card h2 { text-align: center; }
  .rules-card ul { margin: 0 0 16px; padding-left: 18px; color: var(--dim); line-height: 1.4; }
  .rules-card li { margin: 8px 0; }
  .rules-card button { display: block; margin: 0 auto; }
  #rules { z-index: 7; }
  canvas { touch-action: none; border-radius: 18px; }
  .menu { position: relative; }
  .menu > summary { list-style: none; }
  .menu > summary::-webkit-details-marker { display: none; }
  .menu-panel {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 8;
    width: min(260px, 86vw);
    max-height: calc(100dvh - 56px);
    overflow: auto;
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 6px;
    padding: 10px;
    background: #18211c;
    border: 1px solid rgba(228,197,106,0.35);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0,0,0,0.4);
  }
  .menu-panel button, .menu-panel summary, .menu-panel label { text-align: left; }
  .menu-user {
    margin: 2px 4px 6px;
    color: var(--gold);
    font-size: 14px;
    font-weight: 650;
    text-align: center;
  }
  .menu-user:empty { display: none; }
  #eyes-btn { padding: 2px 8px; font-size: 12px; }
  #eyes-btn[hidden] { display: none; }
  .toolbar {
    position: relative;
    flex: 1 1 auto;
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    align-items: center;
    justify-content: flex-end;
    color: var(--dim);
    font-size: 13px;
  }
  .me-chip {
    color: var(--gold);
    font-size: 12px;
    padding: 4px 10px;
    border: 1px solid rgba(228,197,106,0.35);
    border-radius: 999px;
    white-space: nowrap;
  }
  .me-chip.hidden, .hidden { display: none; }
  button, summary {
    background: #1c2620;
    color: var(--ink);
    border: 1px solid rgba(228,197,106,0.35);
    border-radius: 999px;
    padding: 5px 12px;
    font: inherit;
    font-size: 13px;
    cursor: pointer;
  }
  button:hover, summary:hover { border-color: var(--gold); }
  button.primary { background: #3a3220; border-color: var(--gold); }
  button.danger { border-color: #c45b4a; color: #ffb1a6; }
  label { display: flex; gap: 6px; align-items: center; cursor: pointer; }
  .toolbar details { position: relative; color: var(--dim); }
  .toolbar details ul {
    position: absolute;
    right: 0;
    top: calc(100% + 6px);
    z-index: 5;
    width: min(440px, 78vw);
    margin: 0;
    padding: 10px 12px 10px 26px;
    background: #18211c;
    border: 1px solid rgba(228,197,106,0.35);
    border-radius: 12px;
    text-align: left;
    line-height: 1.35;
  }
  .toolbar details li { margin: 4px 0; }
  .modal {
    position: fixed;
    inset: 0;
    background: rgba(6,10,8,0.62);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 4;
  }
  #notice { z-index: 6; }
  #profile { z-index: 7; }
  #crown { z-index: 8; }
  .crown-card { width: min(420px, calc(100% - 24px)); }
  .crown-kicker {
    margin: 0 0 6px;
    letter-spacing: 0.18em;
    text-transform: uppercase;
    font-size: 12px;
    color: var(--gold);
  }
  .crown-line {
    margin: 0 0 4px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 28px;
    color: #f3e6c4;
  }
  #sheet { z-index: 5; }
  .modal.hidden { display: none; }
  .card {
    background: #18211c;
    border: 1px solid var(--gold);
    border-radius: 18px;
    padding: 28px 34px;
    text-align: center;
    min-width: min(420px, calc(100% - 32px));
    box-shadow: 0 24px 60px rgba(0,0,0,0.45);
  }
  .card h2 {
    margin: 0 0 8px;
    font-family: Georgia, serif;
    font-weight: 600;
    color: #f3e6c4;
  }
  .card.rules-card {
    text-align: left;
    max-height: calc(100dvh - 24px);
    overflow: auto;
  }
  .card.rules-card h2 { text-align: center; }
  .card.tone-win h2 { color: #e4c56a; }
  .card.tone-loss h2 { color: #ff8d7a; }
  .card.tone-join h2 { color: #9ddeaf; }
  .card p { margin: 0 0 18px; color: var(--dim); }
  .crown-card .crown-kicker { color: var(--gold); }
  .crown-card .crown-line {
    margin: 0 0 18px;
    font-family: Georgia, "Times New Roman", serif;
    font-size: 28px;
    color: #f3e6c4;
  }
  .notice-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
  .lobby-card { max-height: calc(100vh - 24px); overflow: auto; }
  .brand { display: flex; flex-direction: row; align-items: baseline; gap: 8px; min-width: 0; }
  #room-label { color: var(--gold); font-size: 12px; letter-spacing: 0.04em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  #room-label:empty { display: none; }
  .who-actions { display: flex; gap: 6px; flex-shrink: 0; }
  .lobby-card { width: min(520px, calc(100% - 32px)); text-align: left; }
  .lobby-card h2 { text-align: center; }
  .stack { display: flex; flex-direction: column; gap: 6px; margin: 12px 0; color: var(--dim); font-size: 13px; }
  input[type="text"], input[type="password"] {
    width: 100%;
    background: #101613;
    color: var(--ink);
    border: 1px solid rgba(228,197,106,0.35);
    border-radius: 10px;
    padding: 8px 10px;
    font: inherit;
    user-select: text;
  }
  input[type="text"]:focus, input[type="password"]:focus { outline: 2px solid rgba(228,197,106,0.45); border-color: var(--gold); }
  .tabs { display: flex; gap: 8px; justify-content: center; margin-top: 8px; }
  .tabs button.on { border-color: var(--gold); color: var(--gold); }
  .auth-error { color: #ff8d7a; min-height: 18px; font-size: 13px; margin: 10px 0 0; }
  .who-row { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 8px; }
  .stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin: 12px 0;
  }
  .stats div {
    background: rgba(255,255,255,0.04);
    border-radius: 10px;
    padding: 8px 6px;
    text-align: center;
  }
  .stats span { display: block; color: var(--dim); font-size: 11px; }
  .stats b { font-size: 16px; color: var(--ink); }
  .row { display: flex; gap: 8px; align-items: center; }
  .row input { flex: 1; }
  .rooms-head {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin: 16px 0 8px;
    color: var(--dim);
    font-size: 13px;
  }
  button.tiny { padding: 4px 10px; font-size: 12px; }
  .rooms { display: flex; flex-direction: column; gap: 8px; max-height: 260px; overflow: auto; }
  .room {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 10px;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
  }
  .room b { display: block; color: var(--ink); font-weight: 650; }
  .room span { color: var(--dim); font-size: 12px; }
  .empty-rooms { color: rgba(255,255,255,0.35); font-size: 13px; padding: 8px 2px; }
  .room-actions { display: flex; gap: 6px; flex-shrink: 0; }
  .sheet-card {
    width: min(920px, calc(100% - 16px));
    max-height: calc(100dvh - 16px);
    overflow: auto;
    text-align: left;
  }
  .sheet-head, .profile-online { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
  .profile-online { justify-content: center; margin: 0 0 8px; color: var(--dim); font-size: 13px; }
  .crowns { color: var(--dim); font-size: 13px; }
  .choice { display: flex; gap: 8px; flex-wrap: wrap; margin: 8px 0; }
  .choice button.on { border-color: var(--gold); color: var(--gold); }
  .plist, .tour-list { display: flex; flex-direction: column; gap: 8px; }
  .person, .trow {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 12px;
    background: rgba(255,255,255,0.03);
    border: 1px solid rgba(255,255,255,0.06);
  }
  .person { width: 100%; }
  .person span { margin-left: auto; color: var(--dim); font-size: 12px; }
  .dot { width: 8px; height: 8px; border-radius: 50%; background: #6a726c; display: inline-block; margin-right: 8px; }
  .dot.on { background: #7dcea0; box-shadow: 0 0 0 3px rgba(125,206,160,0.15); }
  .bracket {
    display: flex;
    gap: 28px;
    overflow-x: auto;
    padding: 8px 4px 16px;
    min-height: 280px;
  }
  .round { display: flex; flex-direction: column; justify-content: flex-start; gap: 12px; min-width: 200px; }
  .round h3 {
    margin: 0 0 8px;
    text-align: center;
    font-size: 13px;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--gold);
  }
  .tmatch {
    border: 1px solid rgba(228,197,106,0.35);
    border-radius: 14px;
    padding: 8px;
    background: #121a16;
  }
  .tmatch.live { border-color: var(--gold); box-shadow: 0 0 0 1px rgba(228,197,106,0.25); }
  .slotline {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    padding: 4px 2px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
  }
  .slotline.win b { color: var(--gold); }
  .slotline.lose { opacity: 0.5; }
  .slotline button {
    background: none;
    border: none;
    padding: 0;
    border-radius: 0;
    color: inherit;
    text-decoration: underline;
    text-decoration-color: rgba(228,197,106,0.4);
    text-underline-offset: 2px;
  }
  .tmeta { margin-top: 6px; color: var(--dim); font-size: 12px; font-variant-numeric: tabular-nums; }
  .tacts { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
  @media (max-width: 800px) {
    h1 { font-size: 15px; letter-spacing: 0.06em; }
    .menu-panel button, .menu-panel summary, .guide-toggle { min-height: 36px; }
    .card, .lobby-card { padding: 16px; }
    .row { flex-direction: column; align-items: stretch; }
    .stats { grid-template-columns: 1fr 1fr; }
    .who-row { flex-wrap: wrap; }
  }
  @media (max-height: 720px) {
    .group, .left, .chips, .eight { display: none; }
    .player { padding: 2px 8px; }
  }
