:root {
  color-scheme: light;
  font-family: "Inter", "PingFang SC", "Microsoft YaHei", sans-serif;
  color: #202c28;
  background: #edf0e9;
  --paper: #fffefa;
  --ink: #202c28;
  --muted: #536259;
  --line: #dde4db;
  --soft: #e7ede6;
  --green: #234f40;
  --radius: 20px;
  --gap: clamp(8px, 1.4vw, 16px);
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; width: 100%; height: 100%; overflow: hidden; overflow: clip; overscroll-behavior: none; }
body { position: fixed; inset: 0; }
button, textarea, input, select { font: inherit; }
button { color: inherit; cursor: pointer; touch-action: manipulation; }
button:disabled { cursor: default; opacity: .48; }
button:focus-visible, a:focus-visible, textarea:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid #327060; outline-offset: -2px; }
h1, h2, p { margin: 0; }

.shell {
  width: min(100%, 1232px);
  height: 100vh;
  height: var(--app-height, 100dvh);
  margin-inline: auto;
  padding: max(10px, env(safe-area-inset-top)) max(var(--gap), env(safe-area-inset-right))
    max(10px, env(safe-area-inset-bottom)) max(var(--gap), env(safe-area-inset-left));
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--gap);
  overflow: clip;
}
.topbar { display: flex; align-items: center; gap: clamp(8px, 2vw, 22px); min-height: 42px; }
.brand { display: inline-flex; align-items: center; gap: 9px; font-size: 19px; font-weight: 750; color: inherit; text-decoration: none; white-space: nowrap; }
.brand-mark { display: grid; place-items: center; width: 36px; aspect-ratio: 1; border-radius: 11px; background: var(--green); color: #f1e5ba; font-size: 21px; }
.presence { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 12px; min-width: 0; }
.presence-dot { flex: 0 0 7px; height: 7px; border-radius: 50%; background: #839086; }
.presence[data-connected="true"] .presence-dot { background: #38835c; }
#connection { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-toggle { margin-left: auto; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.unread { min-width: 21px; border-radius: 10px; padding: 1px 4px; text-align: center; background: #c6dbcc; color: #1d4537; }

.workspace { min-width: 0; min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr); gap: var(--gap); }
.chat-open .workspace { grid-template-columns: minmax(0, 1fr) clamp(232px, 30vw, 350px); }
.play-area { display: grid; grid-template-rows: auto minmax(0, 1fr); gap: var(--gap); min-width: 0; min-height: 0; }
@media (min-height: 431px) {
  body:not(.chat-open):not(.keyboard-open) .play-area:has(.chat-preview:not([hidden])) { grid-template-rows: auto minmax(0, 1fr) auto; }
}
.game-picker { display: flex; position: relative; align-items: center; gap: 4px; min-width: 0; background: var(--soft); border-radius: 14px; padding: 4px; }
.open-library { flex: 0 0 auto; white-space: nowrap; margin-inline-end: 2px; background: #dbe7dc; border-color: #cfdcce; }
.game-list { display: flex; gap: 4px; min-width: 0; width: 100%; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; overscroll-behavior: contain; }
.game-list::-webkit-scrollbar, .quick-messages::-webkit-scrollbar { display: none; }
.game-choice { display: flex; flex: 1 0 auto; align-items: center; justify-content: center; gap: 6px; min-height: 40px; padding: 0 10px; white-space: nowrap; border: 1px solid transparent; border-radius: 11px; background: transparent; color: #46594e; font-size: 14px; font-weight: 650; }
.game-choice:hover, .game-choice.suggested { background: #f4f7f0; }
.game-choice.active { background: var(--paper); color: var(--green); border-color: #d7e0d6; box-shadow: 0 1px 2px #23392f12; }
.game-symbol { color: #386351; width: 1em; font-size: 16px; font-weight: 750; }
.picker-arrow { flex: 0 0 27px; height: 34px; padding: 0; background: var(--paper); border: 1px solid var(--line); border-radius: 8px; font-size: 22px; }

.room-card, .conversation, .entry { min-width: 0; min-height: 0; background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: 0 5px 24px #2942330b; }
.room-card { display: flex; flex-direction: column; gap: clamp(4px, 1.2dvh, 12px); padding: clamp(8px, 1.6vw, 22px); overflow: clip; }
.room-heading { display: flex; align-items: start; justify-content: space-between; gap: 8px; flex: 0 0 auto; }
.room-title, .room-tools { display: flex; align-items: center; flex-wrap: wrap; gap: 5px 9px; min-width: 0; }
.room-heading h1, .entry h1 { font-size: clamp(19px, 2.9vw, 29px); font-weight: 750; line-height: 1.2; overflow-wrap: anywhere; }
.room-tools { flex: 0 0 auto; justify-content: end; }
.phase, .thinking { color: #426052; font-size: 12px; white-space: nowrap; }
.phase { padding: 2px 7px; background: #e9efe5; border-radius: 8px; }
.game-view { display: flex; flex: 1 1 0; flex-direction: column; min-width: 0; min-height: 0; overflow: clip; }
.game-controls { display: flex; flex: 0 0 auto; align-items: center; justify-content: center; flex-wrap: wrap; gap: 6px 12px; }
.game-input, .game-form, .chat-form { min-width: 0; }
.game-input { width: min(100%, 530px); }
.game-input > .primary { display: block; margin-inline: auto; }
.game-input:empty { display: none; }
.game-form, .chat-form { display: flex; align-items: stretch; gap: 8px; }
.game-form :is(input, textarea), .chat-form textarea {
  flex: 1; width: 0; min-width: 0; min-height: 40px; max-height: 68px; padding: 8px 10px;
  font-size: 16px; line-height: 1.35; color: var(--ink); border: 1px solid var(--line); border-radius: 10px; background: #f9faf6; resize: none;
}
.result { font-size: 14px; font-weight: 700; color: var(--green); }
.primary, .secondary, .room-actions > summary {
  min-height: 38px; padding: 6px 13px; border: 1px solid transparent; border-radius: 10px; font-size: 14px; font-weight: 650;
}
.primary { background: var(--green); color: #fffefa; white-space: nowrap; }
.primary:hover { background: #326753; }
.secondary, .room-actions > summary { background: #f2f5ef; border-color: var(--line); color: var(--green); }
.secondary:hover, .room-actions > summary:hover { background: #e6ede4; }
.room-actions { position: relative; z-index: 2; }
.room-actions > summary { display: grid; place-items: center; list-style: none; cursor: pointer; }
.room-actions > summary::-webkit-details-marker { display: none; }
.actions-menu { position: absolute; inset-inline-end: 0; inset-block-start: calc(100% + 6px); z-index: 2; display: grid; gap: 3px; min-width: 116px; padding: 5px; background: var(--paper); border: 1px solid var(--line); border-radius: 11px; box-shadow: 0 5px 18px #23392f28; }
.actions-menu button { min-height: 32px; padding: 5px 8px; text-align: left; white-space: nowrap; border: 0; border-radius: 6px; background: transparent; font-size: 13px; }
.actions-menu button:hover { background: var(--soft); }
.actions-menu .danger { color: #903d39; }

.game-moment, .chat-preview { display: flex; align-items: center; gap: 8px; width: 100%; flex: 0 0 auto; min-width: 0; color: #44594d; font-size: 13px; text-align: left; }
.game-moment { border: 0; border-top: 1px solid var(--line); background: transparent; min-height: 32px; padding: 4px 2px 0; }
.chat-preview { background: var(--soft); border: 1px solid var(--line); border-radius: 12px; padding: 6px 11px; min-height: 39px; }
.chat-preview > :first-child { font-weight: 700; white-space: nowrap; color: var(--green); }
#moment-text, #preview-text { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-open .chat-preview { display: none; }
.conversation { display: flex; flex-direction: column; gap: 10px; padding: 14px; overflow: clip; }
.chat-heading { flex: 0 0 auto; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.chat-heading h2, .dialog-body h2 { font-size: 17px; font-weight: 750; }
.chat-reader, #feedback-reader { flex: 1; min-height: 0; background: #eef3ea; border: 1px solid #e2eadf; padding: 10px; border-radius: 12px; }
.text-reader { display: grid; grid-template-rows: auto minmax(0, 1fr) auto; gap: 6px; min-height: 0; min-width: 0; }
.reader-title { color: var(--green); font-weight: 700; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader-title:empty { display: none; }
.reader-content { grid-row: 2; color: var(--ink); white-space: pre-wrap; overflow-wrap: anywhere; overflow: clip; font-size: 15px; line-height: 1.48; }
.reader-content.empty { color: var(--muted); }
.reader-controls { grid-row: 3; display: flex; align-items: center; justify-content: center; gap: 6px; white-space: nowrap; }
.reader-controls .secondary { padding: 2px 7px; min-height: 30px; font-size: 12px; background: var(--paper); }
.reader-count { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.quick-messages { display: flex; flex: 0 0 auto; flex-wrap: nowrap; gap: 5px; overflow-x: auto; overflow-y: hidden; scrollbar-width: none; }
.quick-message { padding: 4px 8px; white-space: nowrap; color: var(--green); background: #f0f4ee; border: 1px solid var(--line); border-radius: 9px; font-size: 12px; }
.chat-form { flex: 0 0 auto; }

.entry { align-self: center; justify-self: center; width: min(100%, 490px); padding: clamp(16px, 5vw, 42px); display: grid; gap: 12px; justify-items: start; }
.entry p, .dialog-body p { color: var(--muted); font-size: 14px; line-height: 1.5; overflow-wrap: anywhere; }
.notice { position: fixed; z-index: 3; top: max(57px, calc(env(safe-area-inset-top) + 46px)); left: 50%; translate: -50% 0; width: min(calc(100% - 20px), 480px); background: #fff2d8; border: 1px solid #e2c993; padding: 9px 12px; box-shadow: 0 4px 18px #533e1526; border-radius: 11px; font-size: 13px; overflow-wrap: anywhere; }
.notice button { margin: 4px; }
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 0; background: var(--paper); color: var(--ink); width: min(92vw, 450px); max-height: calc(var(--app-height, 100dvh) - 20px); overflow: clip; }
dialog::backdrop { background: #172c25a0; }
.dialog-body { display: flex; flex-direction: column; gap: 12px; padding: 16px; }
.dialog-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: end; }
.feedback-body { height: min(420px, calc(var(--app-height, 100dvh) - 22px)); }
.library-body { height: min(424px, calc(var(--app-height, 100dvh) - 22px)); }
#library-dialog { width: min(94vw, 540px); }
.library-filters { display: grid; grid-template-columns: minmax(90px, .85fr) minmax(0, 1.3fr); gap: 8px; }
.library-filters :is(input, select) { min-width: 0; min-height: 37px; padding: 4px 8px; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; background: #f8faf5; font-size: 16px; }
.library-content { flex: 1; min-height: 0; position: relative; }
.library-content > p { position: absolute; inset: 12px 0 auto; text-align: center; }
.library-grid { height: 100%; display: grid; align-content: start; grid-template-columns: repeat(2, minmax(0, 1fr)); grid-auto-rows: 54px; gap: 7px; overflow: clip; }
.library-game { text-align: left; min-width: 0; display: flex; align-items: center; gap: 7px; padding: 5px 7px; border: 1px solid var(--line); border-radius: 10px; background: #f4f7f1; }
.library-game:hover, .library-game.active { background: #e5eee2; border-color: #a9c4ac; }
.library-icon { display: grid; place-items: center; flex: 0 0 26px; height: 26px; border-radius: 7px; background: #e0ebdf; color: var(--green); }
.library-game-copy { min-width: 0; display: grid; gap: 1px; }
.library-game-copy > * { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.library-game strong { font-size: 14px; }
.library-game small { color: var(--muted); font-size: 12px; }
.library-pages { flex: 0 0 auto; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

@media (max-width: 790px) and (orientation: portrait), (max-width: 580px) {
  .chat-open .workspace { grid-template-columns: minmax(0, 1fr); }
  .chat-open .play-area { display: none; }
  .room-card, .conversation { --radius: 15px; }
  .game-choice { min-height: 36px; font-size: 13px; padding-inline: 6px; gap: 4px; }
  .game-symbol { font-size: 14px; }
}

@media (max-height: 510px) {
  :root { --gap: 5px; }
  .shell { padding-block: max(4px, env(safe-area-inset-top)) max(4px, env(safe-area-inset-bottom)); }
  .topbar { min-height: 32px; }
  .brand-mark { width: 28px; font-size: 16px; border-radius: 8px; }
  .brand { font-size: 16px; }
  .game-picker { padding-block: 2px; }
  .game-choice, .picker-arrow, .primary, .secondary, .room-actions > summary { min-height: 31px; }
  .game-choice { padding-block: 0; }
  .game-moment, .chat-preview { min-height: 26px; }
  .room-card, .conversation { padding: 7px; gap: 5px; }
  .reader-content { font-size: 14px; }
  .library-body { gap: 6px; padding: 9px 12px; }
  .library-grid { grid-auto-rows: 43px; gap: 4px; }
}

.keyboard-open { --gap: 5px; }
.keyboard-open .chat-preview { display: none; }
.keyboard-open .room-card { gap: 4px; }
@media (max-height: 430px) { .chat-preview { display: none; } }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; } }
