:root {
  color-scheme: light;
  --bg: #f3f7f2;
  --surface: #ffffff;
  --surface-strong: #fef9e8;
  --ink: #17211c;
  --muted: #68746d;
  --line: #d9e1d8;
  --green: #2f8f6a;
  --green-dark: #1e6b52;
  --mint: #ccebdc;
  --yellow: #f6c453;
  --coral: #ef6b5b;
  --blue: #477fba;
  --shadow: 0 18px 48px rgba(36, 54, 44, 0.12);
  --radius: 8px;
  font-family:
    Inter, "Microsoft YaHei", "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(47, 143, 106, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(47, 143, 106, 0.08) 1px, transparent 1px),
    var(--bg);
  background-size: 42px 42px;
  color: var(--ink);
}

button,
input {
  font: inherit;
}

button {
  border: 0;
  border-radius: var(--radius);
  color: white;
  background: var(--green);
  cursor: pointer;
  transition:
    transform 160ms ease,
    background 160ms ease,
    border-color 160ms ease,
    box-shadow 160ms ease;
}

button:hover:not(:disabled) {
  background: var(--green-dark);
  transform: translateY(-1px);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
  color: var(--ink);
  outline: none;
}

input:focus {
  border-color: var(--green);
  box-shadow: 0 0 0 3px rgba(47, 143, 106, 0.16);
}

.app-shell {
  width: min(1540px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 16px 0 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 76px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.brand-mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--yellow);
  font-size: 22px;
  font-weight: 900;
  box-shadow: 5px 5px 0 var(--ink);
}

.brand h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.1;
  letter-spacing: 0;
}

.brand p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.room-tools {
  display: none;
  align-items: center;
  gap: 8px;
}

body.is-in-game .room-tools {
  display: flex;
}

.room-code {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 220px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.82);
}

.room-code span,
.meta-label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.room-code span {
  min-width: 30px;
  white-space: nowrap;
}

.room-code input {
  border: 0;
  padding: 0;
  background: transparent;
  font-weight: 800;
  text-transform: uppercase;
  box-shadow: none;
}

.icon-button {
  width: 42px;
  height: 42px;
  font-size: 20px;
}

.secondary-button,
.tool-button,
.admin-link {
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
}

.danger-button {
  border-color: rgba(239, 107, 91, 0.45);
  color: var(--coral);
}

.secondary-button:hover:not(:disabled),
.tool-button:hover:not(:disabled),
.admin-link:hover {
  border-color: var(--green);
  background: var(--mint);
}

.secondary-button {
  min-height: 42px;
  padding: 0 14px;
  font-weight: 800;
}

.admin-link {
  display: inline-grid;
  min-height: 42px;
  place-items: center;
  padding: 0 14px;
  font-size: 14px;
  font-weight: 900;
  text-decoration: none;
}

.compact {
  min-height: 34px;
  padding: 0 12px;
  font-size: 13px;
}

.join-screen {
  display: grid;
  min-height: calc(100vh - 116px);
  place-items: center;
}

.join-panel {
  display: grid;
  grid-template-columns: minmax(260px, 0.85fr) minmax(320px, 1fr);
  width: min(980px, 100%);
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow), 8px 8px 0 var(--ink);
}

.join-art {
  position: relative;
  min-height: 430px;
  background:
    radial-gradient(circle at 20% 20%, rgba(246, 196, 83, 0.55), transparent 28%),
    linear-gradient(135deg, #d9f0e4, #fff2c4);
}

.task-card {
  position: absolute;
  top: 42px;
  left: 34px;
  width: 168px;
  padding: 18px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: white;
  font-weight: 900;
  box-shadow: 7px 7px 0 rgba(23, 33, 28, 0.9);
}

.task-card::after {
  display: block;
  width: 92px;
  height: 9px;
  margin-top: 18px;
  background: repeating-linear-gradient(90deg, var(--green), var(--green) 18px, var(--yellow) 18px, var(--yellow) 28px);
  content: "";
}

.paint-splash {
  position: absolute;
  border: 2px solid var(--ink);
  border-radius: 50%;
}

.splash-a {
  right: 50px;
  top: 62px;
  width: 86px;
  height: 86px;
  background: var(--coral);
}

.splash-b {
  left: 72px;
  bottom: 66px;
  width: 70px;
  height: 70px;
  background: var(--blue);
}

.goose-card {
  position: absolute;
  right: 54px;
  bottom: 54px;
  width: 210px;
  height: 190px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background: #fffdf5;
  box-shadow: 8px 8px 0 var(--ink);
}

.goose-body {
  position: absolute;
  right: 34px;
  bottom: 28px;
  width: 112px;
  height: 76px;
  border: 2px solid var(--ink);
  border-radius: 60% 48% 48% 55%;
  background: white;
}

.goose-head {
  position: absolute;
  top: 38px;
  left: 42px;
  width: 84px;
  height: 104px;
  border: 2px solid var(--ink);
  border-radius: 60% 60% 44% 44%;
  background: white;
}

.goose-head::before {
  position: absolute;
  top: 38px;
  left: -28px;
  width: 34px;
  height: 18px;
  border: 2px solid var(--ink);
  border-right: 0;
  border-radius: 18px 0 0 18px;
  background: var(--yellow);
  content: "";
}

.join-copy {
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 48px;
}

.join-copy h2 {
  margin: 0;
  font-size: clamp(28px, 4vw, 46px);
  line-height: 1.08;
  letter-spacing: 0;
}

.join-copy p {
  margin: 18px 0 28px;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.7;
}

.join-mode-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 14px;
}

.join-mode-btn {
  min-height: 44px;
  border: 1px solid var(--line);
  background: white;
  color: var(--ink);
  font-weight: 900;
}

.join-mode-btn.active {
  border-color: var(--ink);
  background: var(--yellow);
}

.join-form {
  display: grid;
  gap: 14px;
}

.join-form label,
.avatar-picker {
  display: grid;
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fbfdfb;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.form-label {
  color: var(--muted);
}

.emoji-choices {
  display: grid;
  grid-template-columns: repeat(8, minmax(34px, 1fr));
  gap: 6px;
}

.system-avatar-choices {
  grid-template-columns: repeat(4, minmax(56px, 1fr));
}

.emoji-choice {
  position: relative;
  display: grid;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 4px;
  background: white;
  color: var(--ink);
  font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", system-ui, sans-serif;
  font-size: 20px;
}

.system-avatar-choices .emoji-choice {
  min-height: 62px;
}

.emoji-choice.active {
  border-color: var(--ink);
  background: var(--mint);
  box-shadow: inset 0 0 0 2px white;
}

.system-avatar {
  display: block;
  aspect-ratio: 1;
  width: 100%;
  border-radius: 50%;
  background-image: url("./images/default-avatars.png");
  background-repeat: no-repeat;
  background-size: 400% 400%;
}

.emoji-choice .system-avatar {
  position: absolute;
  inset: 4px;
  width: auto;
  max-width: none;
}

.avatar .system-avatar {
  width: 100%;
}

.avatar-upload {
  position: relative;
  min-height: 42px;
  place-items: center;
  border: 1px dashed #aabbb0;
  border-radius: var(--radius);
  background: #fbfdfb;
  color: var(--ink);
  cursor: pointer;
}

.avatar-upload input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.avatar-hint {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.join-form input {
  min-height: 48px;
  padding: 0 14px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 700;
}

.join-form button,
.host-controls button,
.guess-form button {
  min-height: 46px;
  padding: 0 16px;
  font-weight: 900;
}

.game-grid {
  display: grid;
  grid-template-columns: minmax(220px, 280px) minmax(520px, 1fr) minmax(260px, 330px);
  gap: 14px;
  align-items: stretch;
}

.panel,
.studio {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.9);
  box-shadow: 0 14px 36px rgba(36, 54, 44, 0.08);
}

.side-panel {
  display: flex;
  height: calc(100vh - 116px);
  min-height: 0;
  flex-direction: column;
  padding: 14px;
}

.panel-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.chat-panel .panel-heading h2 {
  order: 0;
}

#hostBadge {
  order: 3;
}

.panel-heading h2,
.rules-box h3,
.word-bank h3 {
  margin: 0;
  font-size: 16px;
  line-height: 1.2;
}

#playerCount,
#hostBadge {
  color: var(--green-dark);
  font-size: 12px;
  font-weight: 900;
}

.players-list {
  display: grid;
  gap: 6px;
}

.player-row {
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  align-items: center;
  gap: 7px;
  padding: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: white;
}

.player-row.is-drawer {
  border-color: var(--green-dark);
  background: #fffefa;
  box-shadow:
    0 0 0 2px rgba(246, 196, 83, 0.9),
    0 8px 18px rgba(47, 143, 106, 0.16);
}

.avatar {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  background: var(--mint);
  color: var(--green-dark);
  font-size: 15px;
  font-weight: 900;
  overflow: hidden;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.player-name {
  min-width: 0;
  overflow: hidden;
  font-weight: 850;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player-meta {
  color: var(--muted);
  font-size: 11px;
  font-weight: 750;
}

.score {
  color: var(--ink);
  font-size: 16px;
  font-weight: 950;
}

.rules-box,
.word-bank {
  margin-top: auto;
  border: 1px dashed #bdd0c2;
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface-strong);
}

.rules-box ul {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.65;
}

.studio {
  display: flex;
  height: calc(100vh - 116px);
  min-height: 0;
  flex-direction: column;
  gap: 10px;
  padding: 12px;
}

.round-card {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fffefa;
}

body.is-in-game.status-drawing .round-card {
  display: none;
}

.round-card div:not(.timer) {
  display: grid;
  gap: 4px;
  min-width: 0;
}

.round-card strong {
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.timer {
  display: grid;
  width: 54px;
  height: 54px;
  place-items: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--yellow);
  font-size: 20px;
  font-weight: 950;
}

.word-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  min-height: 44px;
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--green-dark);
  color: white;
  font-weight: 900;
}

.word-strip .timer {
  flex: 0 0 auto;
}

.word-choices {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.word-choices button {
  min-height: 44px;
  border: 1px solid var(--line);
  background: #fffefa;
  color: var(--ink);
  font-weight: 900;
}

.canvas-wrap {
  position: relative;
  flex: 1;
  min-height: 420px;
  overflow: hidden;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  background:
    linear-gradient(45deg, rgba(104, 116, 109, 0.08) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(104, 116, 109, 0.08) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(104, 116, 109, 0.08) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(104, 116, 109, 0.08) 75%);
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

#drawingCanvas {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: default;
}

.canvas-wrap.can-draw {
  touch-action: none;
}

body.is-drawing-active {
  overscroll-behavior: none;
  touch-action: none;
  user-select: none;
}

.canvas-wrap.can-draw.cursor-pen #drawingCanvas {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cpath d='M23 3l6 6-17 17-8 2 2-8z' fill='%23f6c453' stroke='%2317211c' stroke-width='2'/%3E%3Cpath d='M19 7l6 6' stroke='%23fff' stroke-width='2'/%3E%3C/svg%3E") 4 28, crosshair;
}

.canvas-wrap.can-draw.cursor-eraser #drawingCanvas {
  cursor: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='32' height='32' viewBox='0 0 32 32'%3E%3Cg transform='rotate(-24 16 16)'%3E%3Crect x='7' y='10' width='18' height='13' rx='3' fill='%23ffffff' stroke='%2317211c' stroke-width='2'/%3E%3Cpath d='M13 10v13' stroke='%23ef6b5b' stroke-width='2'/%3E%3C/g%3E%3C/svg%3E") 16 16, cell;
}

.canvas-lock {
  position: absolute;
  right: 12px;
  bottom: 12px;
  border: 1px solid rgba(23, 33, 28, 0.14);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.86);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  pointer-events: none;
}

.canvas-wrap.can-draw .canvas-lock {
  color: var(--green-dark);
}

.toolbar {
  display: none;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  background: white;
  transition:
    max-height 180ms ease,
    opacity 180ms ease,
    padding 180ms ease,
    border-width 180ms ease;
}

body.can-use-tools .toolbar {
  display: flex;
}

.tool-group {
  position: relative;
  display: flex;
  gap: 6px;
}

.color-toggle {
  display: grid;
  width: 34px;
  height: 34px;
  place-items: center;
  border: 1px solid var(--line);
  background: white;
  padding: 0;
}

.swatch-panel {
  position: absolute;
  left: 0;
  bottom: calc(100% + 8px);
  z-index: 8;
  display: grid;
  grid-template-columns: repeat(4, 30px);
  gap: 7px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  background: white;
  box-shadow: 0 12px 28px rgba(23, 33, 28, 0.16);
}

.swatch {
  width: 30px;
  height: 30px;
  border: 2px solid white;
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--line);
}

.swatch.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 2px var(--yellow);
}

.range-tool {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
}

.range-tool input {
  width: 110px;
  border: 0;
  box-shadow: none;
}

.range-tool output {
  min-width: 22px;
  color: var(--ink);
  text-align: right;
}

.tool-button {
  display: grid;
  min-width: 38px;
  min-height: 34px;
  place-items: center;
  padding: 0 10px;
  font-size: 18px;
  font-weight: 900;
}

.tool-button img {
  width: 20px;
  height: 20px;
  object-fit: contain;
  pointer-events: none;
}

.tool-button.active {
  border-color: var(--ink);
  background: var(--yellow);
}

.tool-button.danger {
  color: var(--coral);
}

.host-controls {
  display: none;
  flex: 0 0 auto;
  grid-template-columns: 1fr;
  gap: 8px;
}

body.is-host .host-controls {
  display: grid;
}

.host-controls #startBtn {
  grid-column: auto;
}

.messages {
  display: flex;
  flex: 1 1 auto;
  flex-direction: column;
  gap: 8px;
  min-height: 0;
  margin: 12px 0;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  background: #fbfdfb;
}

.chat-panel {
  min-height: 0;
  overflow: hidden;
}

.chat-panel .word-bank {
  display: none;
}

.chat-panel .panel-heading,
.guess-form,
.chat-panel .word-bank {
  flex: 0 0 auto;
}

.message {
  max-width: 92%;
  border-radius: var(--radius);
  padding: 8px 10px;
  background: white;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 0 1px 0 rgba(23, 33, 28, 0.05);
}

.message.system {
  align-self: center;
  border: 1px dashed #bdd0c2;
  background: var(--surface-strong);
  color: var(--muted);
  font-weight: 750;
}

.message.correct {
  border: 1px solid var(--line);
  background: white;
  color: var(--muted);
  font-weight: 750;
}

.message .name {
  display: block;
  margin-bottom: 2px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
}

.guess-form {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.guess-form input {
  min-height: 44px;
  padding: 0 12px;
}

.word-bank p {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  z-index: 20;
  max-width: min(460px, calc(100vw - 32px));
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: white;
  font-size: 13px;
  font-weight: 800;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 16px);
  transition:
    opacity 180ms ease,
    transform 180ms ease;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 28;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(12, 20, 15, 0.28);
}

.settings-card {
  display: grid;
  width: min(380px, calc(100vw - 32px));
  gap: 12px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 16px;
  background: white;
  box-shadow: 8px 8px 0 var(--ink), 0 22px 48px rgba(12, 20, 15, 0.18);
}

.settings-head,
.settings-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.settings-head strong {
  font-size: 18px;
}

.settings-card label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 850;
}

.settings-card input[type="number"] {
  min-height: 42px;
  padding: 0 10px;
  color: var(--ink);
  font-weight: 850;
}

.toggle-row {
  grid-template-columns: auto 1fr;
  align-items: center;
}

.toggle-row input {
  width: 18px;
  height: 18px;
}

.settings-actions button {
  min-height: 40px;
  padding: 0 14px;
  font-weight: 900;
}

.round-notice {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 20, 15, 0.38);
  pointer-events: none;
}

.round-notice-card {
  width: min(560px, calc(100vw - 32px));
  border: 3px solid var(--ink);
  border-radius: var(--radius);
  padding: 26px;
  background: #fffefa;
  box-shadow: 10px 10px 0 var(--ink), 0 22px 60px rgba(12, 20, 15, 0.24);
  text-align: center;
  animation: noticePop 260ms ease both;
}

.round-notice-card span {
  display: inline-block;
  margin-bottom: 10px;
  color: var(--green-dark);
  font-size: 14px;
  font-weight: 950;
}

.round-notice-card strong {
  display: block;
  font-size: clamp(34px, 7vw, 62px);
  line-height: 1.02;
  letter-spacing: 0;
}

.round-notice-card p {
  margin: 12px 0 0;
  color: var(--muted);
  font-size: clamp(16px, 3vw, 22px);
  font-weight: 850;
}

.leaderboard-modal {
  position: fixed;
  inset: 0;
  z-index: 32;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(12, 20, 15, 0.38);
}

.leaderboard-card {
  display: grid;
  width: min(420px, calc(100vw - 32px));
  gap: 12px;
  border: 2px solid var(--ink);
  border-radius: var(--radius);
  padding: 16px;
  background: white;
  box-shadow: 8px 8px 0 var(--ink), 0 22px 48px rgba(12, 20, 15, 0.2);
}

.leaderboard-list {
  display: grid;
  gap: 8px;
}

.leaderboard-row {
  display: grid;
  grid-template-columns: 24px 34px 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px;
  background: #fbfdfb;
}

@keyframes noticePop {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.96);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@media (max-width: 1120px) {
  .game-grid {
    grid-template-columns: 220px minmax(420px, 1fr);
  }

  .chat-panel {
    grid-column: 1 / -1;
    min-height: 420px;
  }
}

@media (max-width: 760px) {
  .app-shell {
    width: min(100vw - 16px, 720px);
    padding: 8px 0 16px;
  }

  body.is-in-game {
    overflow: hidden;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
  }

  body:not(.is-in-game) .topbar {
    min-height: auto;
    align-items: center;
    padding: 4px 0 8px;
  }

  body:not(.is-in-game) .brand {
    gap: 10px;
  }

  body:not(.is-in-game) .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 18px;
    box-shadow: 3px 3px 0 var(--ink);
  }

  body:not(.is-in-game) .brand h1 {
    font-size: 20px;
  }

  body:not(.is-in-game) .brand p {
    display: none;
  }

  body.is-in-game .app-shell {
    width: calc(100vw - 8px);
    height: 100dvh;
    padding: 4px 0;
  }

  body.is-in-game .topbar {
    min-height: 42px;
    align-items: center;
    flex-direction: row;
    gap: 8px;
  }

  body.is-in-game .brand {
    gap: 8px;
  }

  body.is-in-game .brand-mark {
    width: 38px;
    height: 38px;
    font-size: 18px;
    box-shadow: 3px 3px 0 var(--ink);
  }

  body.is-in-game .brand h1 {
    font-size: 18px;
  }

  body.is-in-game .brand p,
  body.is-in-game .rules-box,
  body.is-in-game .word-bank {
    display: none;
  }

  body.is-in-game .brand {
    display: none;
  }

  body.is-in-game .brand h1 {
    display: none;
  }

  body.is-in-game .room-tools {
    display: grid;
    width: 100%;
    grid-template-columns: minmax(0, 1fr) 40px 54px;
    gap: 6px;
  }

  body.is-in-game .room-code {
    min-width: 0;
    max-width: none;
    padding: 6px 8px;
  }

  body.is-in-game .room-code input {
    min-width: 0;
    font-size: 13px;
  }

  body.is-in-game .admin-link {
    display: none;
  }

  body.is-in-game #leaveBtn {
    display: inline-grid;
    min-height: 38px;
    place-items: center;
    padding: 0 8px;
    font-size: 13px;
  }

  .room-code {
    width: 100%;
  }

  .join-screen {
    min-height: auto;
    align-items: start;
    place-items: start center;
  }

  .join-panel {
    grid-template-columns: 1fr;
    width: 100%;
    border-width: 1px;
    box-shadow: 4px 4px 0 var(--ink);
  }

  .join-art {
    display: none;
  }

  .join-copy {
    padding: 16px;
  }

  .join-copy h2 {
    font-size: 26px;
    line-height: 1.12;
  }

  .join-copy p {
    margin: 10px 0 14px;
    font-size: 14px;
    line-height: 1.45;
  }

  .join-mode-tabs {
    gap: 6px;
    margin-bottom: 10px;
  }

  .join-mode-btn {
    min-height: 40px;
    font-size: 14px;
  }

  .join-form {
    gap: 10px;
  }

  .join-form label,
  .avatar-picker {
    gap: 5px;
    font-size: 12px;
  }

  .join-form input {
    min-height: 42px;
    padding: 0 10px;
    font-size: 15px;
  }

  .join-form button {
    min-height: 42px;
  }

  .emoji-choices {
    grid-template-columns: repeat(4, minmax(58px, 1fr));
    gap: 5px;
  }

  .emoji-choice {
    min-height: 58px;
    font-size: 18px;
  }

  .emoji-choice .system-avatar {
    inset: 5px;
  }

  .avatar-upload {
    min-height: 38px;
  }

  .avatar-hint {
    font-size: 11px;
  }

  .goose-card {
    right: 28px;
    bottom: 28px;
    transform: scale(0.78);
    transform-origin: right bottom;
  }

  .game-grid {
    grid-template-columns: 1fr;
  }

  body.is-in-game .game-grid {
    display: flex;
    flex-direction: column;
    height: calc(100dvh - 48px);
    gap: 6px;
    overflow: hidden;
  }

  body.is-in-game:not(.can-use-tools) .game-grid {
    grid-template-rows: none;
  }

  body.is-in-game.can-use-tools .game-grid {
    grid-template-rows: none;
  }

  .side-panel,
  .studio {
    height: auto;
    min-height: auto;
  }

  .studio {
    order: -1;
  }

  body.is-in-game .player-panel {
    flex: 0 0 auto;
    order: -2;
    display: grid;
    min-height: 0;
    max-height: 92px;
    grid-template-columns: auto minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 7px;
    overflow: hidden;
  }

  body.is-in-game .player-panel .panel-heading {
    display: grid;
    flex: 0 0 auto;
    gap: 2px;
    margin: 0;
  }

  body.is-in-game .player-panel .panel-heading h2 {
    font-size: 13px;
    white-space: nowrap;
  }

  body.is-in-game #playerCount {
    font-size: 11px;
    white-space: nowrap;
  }

  body.is-in-game .players-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(74px, 1fr));
    min-width: 0;
    gap: 4px;
    overflow: hidden;
    padding-bottom: 2px;
  }

  body.is-in-game .player-row {
    min-width: 0;
    grid-template-columns: 22px minmax(0, 1fr) auto;
    gap: 4px;
    padding: 4px;
  }

  body.is-in-game .avatar {
    width: 22px;
    height: 22px;
    font-size: 12px;
  }

  body.is-in-game .player-name {
    font-size: 11px;
  }

  body.is-in-game .player-meta {
    font-size: 9px;
  }

  body.is-in-game .score {
    font-size: 12px;
  }

  body.is-in-game .studio {
    display: flex;
    flex-direction: column;
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
    padding: 6px;
    gap: 6px;
  }

  body.is-in-game .chat-panel {
    display: flex;
    flex: 0 0 min(34dvh, 260px);
    grid-column: auto;
    min-height: 0;
    overflow: hidden;
    padding: 6px;
  }

  body.is-in-game.can-use-tools .chat-panel {
    flex-basis: min(24dvh, 180px);
  }

  .round-card {
    grid-template-columns: 1fr 1fr;
  }

  body.is-in-game .round-card {
    display: none;
  }

  body.is-in-game .meta-label {
    font-size: 10px;
  }

  body.is-in-game .round-card strong {
    font-size: 13px;
  }

  .timer {
    width: 48px;
    height: 48px;
  }

  body.is-in-game .timer {
    width: 36px;
    height: 36px;
    font-size: 15px;
  }

  body.is-in-game .word-strip {
    min-height: 34px;
    padding: 5px 8px;
    font-size: 13px;
  }

  body.is-in-game .word-choices {
    grid-template-columns: 1fr;
    gap: 5px;
  }

  body.is-in-game .word-choices button {
    min-height: 36px;
    font-size: 13px;
  }

  .canvas-wrap {
    min-height: min(62vh, 460px);
  }

  body.is-in-game .canvas-wrap {
    min-height: 0;
    flex: 1;
    height: 100%;
    border-width: 1px;
  }

  body.is-in-game .toolbar {
    grid-template-columns: 34px minmax(104px, 1fr) repeat(4, minmax(32px, 36px));
    align-items: center;
    gap: 5px;
    overflow: visible;
    max-height: 78px;
    padding: 5px;
  }

  body.is-in-game.can-use-tools .toolbar {
    display: grid;
  }

  body.is-in-game.is-drawing-active .toolbar {
    opacity: 1;
  }

  body.is-in-game .swatches {
    min-width: 0;
  }

  body.is-in-game .swatch {
    width: 26px;
    height: 26px;
  }

  body.is-in-game .color-toggle {
    width: 32px;
    height: 32px;
  }

  body.is-in-game .swatch-panel {
    grid-template-columns: repeat(4, 26px);
    bottom: calc(100% + 6px);
  }

  body.is-in-game .range-tool {
    min-width: 0;
    padding: 0 6px;
  }

  body.is-in-game .range-tool input {
    width: 100%;
  }

  body.is-in-game .tool-button {
    min-width: 0;
    padding: 0;
  }

  body.is-in-game .panel-heading {
    margin-bottom: 6px;
  }

  body.is-in-game .panel-heading h2 {
    font-size: 15px;
  }

  body.is-in-game .host-controls {
    width: 100%;
    min-width: 0;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 4px;
  }

  body.is-in-game .host-controls #startBtn {
    grid-column: auto;
  }

  body.is-in-game .host-controls button,
  body.is-in-game .guess-form button {
    min-height: 28px;
    padding: 0 4px;
    font-size: 11px;
  }

  .messages {
    min-height: 260px;
  }

  body.is-in-game .messages {
    flex: 1;
    min-height: 0;
    margin: 5px 0;
    padding: 6px;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-y;
  }

  body.is-in-game .message {
    max-width: 100%;
    padding: 6px 8px;
    font-size: 12px;
  }

  body.is-in-game .guess-form {
    grid-template-columns: 1fr 64px;
    gap: 6px;
  }

  body.is-in-game .guess-form input {
    min-height: 36px;
    padding: 0 10px;
    font-size: 13px;
  }

  .round-notice-card {
    padding: 20px;
  }
}
