:root {
  color-scheme: light;
  font-family:
    "Arial Rounded MT Bold", "Trebuchet MS", ui-sans-serif, system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  --ink: #101014;
  --muted: #5c6578;
  --paper: #fffdf5;
  --panel: #fffaf0;
  --panel-2: #edf9ff;
  --line: #101014;
  --mint: #44d7a8;
  --cyan: #58c7ff;
  --blue: #3558ff;
  --pink: #ff6b8f;
  --red: #ef4444;
  --gold: #ffd166;
  --green: #15803d;
  --bad: #b42318;
  --shadow: 6px 6px 0 var(--ink);
  --soft-shadow: 3px 3px 0 var(--ink);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background:
    linear-gradient(90deg, rgba(16, 16, 20, 0.05) 1px, transparent 1px),
    linear-gradient(180deg, rgba(16, 16, 20, 0.05) 1px, transparent 1px),
    linear-gradient(135deg, #eaf9ff 0%, #fff8dc 42%, #ffe7ef 100%);
  background-size: 18px 18px, 18px 18px, 100% 100%;
  color: var(--ink);
  overscroll-behavior: none;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled,
input:disabled {
  cursor: not-allowed;
  filter: grayscale(0.6);
  opacity: 0.58;
  transform: none;
}

button:active:not(:disabled) {
  transform: translate(3px, 3px);
  box-shadow: 0 0 0 var(--ink);
}

button:focus-visible,
input:focus-visible {
  outline: 4px solid var(--gold);
  outline-offset: 2px;
}

.shell {
  width: min(1480px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 14px 0;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(1.95rem, 3.4vw, 4rem);
  line-height: 0.9;
  letter-spacing: 0;
  text-shadow:
    3px 3px 0 var(--gold),
    6px 6px 0 var(--cyan);
}

h2 {
  font-size: 1.05rem;
  line-height: 1.18;
  letter-spacing: 0;
}

.eyebrow,
.meta-label {
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.72rem;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.identity-strip,
.room-row,
.lobby-controls,
.settings-block,
.tool-dock,
.round-strip,
.room-share,
.chat-form {
  display: flex;
  align-items: center;
  gap: 10px;
}

.game-layout {
  display: grid;
  grid-template-columns: minmax(260px, 320px) minmax(420px, 1fr) minmax(260px, 320px);
  gap: 18px;
  align-items: start;
}

.side-panel,
.stage-panel {
  background: var(--panel);
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.side-panel {
  padding: 18px;
  min-height: min(690px, calc(100vh - 120px));
}

.stage-panel {
  position: relative;
  display: grid;
  grid-template-rows: auto auto minmax(0, auto) auto auto;
  padding: 14px;
  min-height: 0;
  overflow: hidden;
  transition: background 0.18s steps(3, end), box-shadow 0.18s steps(3, end);
}

.stage-panel[data-phase="drawing"] {
  background: #f4fff4;
}

.stage-panel[data-phase="judging"] {
  background: #fff7e3;
}

.stage-panel[data-phase="reveal"],
.stage-panel[data-phase="finished"] {
  background: #fff2f7;
}

.section-heading {
  display: grid;
  gap: 4px;
  margin-bottom: 14px;
}

.section-heading.compact {
  margin-top: 22px;
}

.field-label,
.slider-label {
  display: block;
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.78rem;
  font-weight: 900;
  margin-bottom: 6px;
}

.text-field {
  width: 100%;
  height: 44px;
  border: 3px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: var(--soft-shadow);
  color: var(--ink);
  padding: 0 12px;
  outline: none;
}

.text-field:focus {
  background: #fff6bf;
}

.code-field {
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 900;
}

.room-row {
  align-items: end;
  margin-top: 14px;
}

.room-row > div {
  flex: 1;
}

.button,
.tool-button,
.icon-button,
.swatch {
  border: 3px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--soft-shadow);
  min-height: 38px;
  font-weight: 950;
}

.button,
.tool-button,
.icon-button {
  transition: transform 0.08s ease, box-shadow 0.08s ease, background 0.1s ease;
}

.button:hover:not(:disabled),
.tool-button:hover:not(:disabled),
.icon-button:hover:not(:disabled),
.swatch:hover:not(:disabled) {
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.button {
  padding: 0 12px;
}

.button.primary {
  background: var(--mint);
  color: var(--ink);
}

.button.secondary {
  background: var(--cyan);
  color: var(--ink);
}

.button.accent {
  background: var(--pink);
  color: var(--ink);
}

.tool-button,
.icon-button {
  background: #ffffff;
  color: var(--ink);
  padding: 0 9px;
}

.tool-button.active {
  background: var(--ink);
  color: #ffffff;
}

.status-pill {
  border: 3px solid var(--line);
  border-radius: 999px;
  background: #ffffff;
  box-shadow: var(--soft-shadow);
  color: var(--muted);
  display: inline-grid;
  min-height: 38px;
  place-items: center;
  padding: 0 12px;
  font-size: 0.82rem;
  font-weight: 950;
}

.status-pill.good {
  background: #d9ffe7;
  color: var(--green);
}

.status-pill.bad {
  background: #ffe1dc;
  color: var(--bad);
}

.room-share {
  justify-content: space-between;
  background: var(--panel-2);
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
  margin: 16px 0;
  padding: 12px;
}

#roomCodeLabel {
  display: block;
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 1.5rem;
  letter-spacing: 0.12em;
}

.lobby-controls {
  align-items: stretch;
}

.lobby-controls .button {
  flex: 1;
}

.settings-block {
  margin-top: 16px;
}

.number-field {
  flex: 1;
}

.rank-list {
  display: grid;
  gap: 9px;
  list-style: none;
  margin: 0;
  padding: 0;
}

.rank-item {
  display: grid;
  grid-template-columns: 32px 1fr auto;
  align-items: center;
  gap: 10px;
  min-height: 50px;
  background: #ffffff;
  border: 3px solid var(--line);
  border-radius: 6px;
  box-shadow: 2px 2px 0 var(--ink);
  padding: 8px 10px;
}

.rank-item.current-player {
  background: #fff6bf;
  box-shadow: 3px 3px 0 var(--blue);
}

.rank-index {
  color: var(--blue);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-weight: 950;
}

.rank-name {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-meta {
  color: var(--muted);
  display: block;
  font-size: 0.76rem;
  margin-top: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.rank-score {
  color: var(--green);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-weight: 950;
}

.leaderboard-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 10px;
}

.leaderboard-tab {
  min-height: 36px;
  border: 3px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  box-shadow: var(--soft-shadow);
  color: var(--ink);
  font-weight: 950;
}

.leaderboard-tab.active {
  background: var(--gold);
  transform: translate(2px, 2px);
  box-shadow: 1px 1px 0 var(--ink);
}

.leaderboard-tab:hover:not(.active) {
  background: #fff6bf;
}

.compact-tabs {
  grid-template-columns: 1fr 1fr;
  margin-top: 4px;
}

.score-panel[hidden] {
  display: none;
}

.profile-card {
  display: grid;
  gap: 9px;
  background: var(--panel-2);
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
  margin-top: 12px;
  padding: 12px;
}

.profile-card > strong {
  font-size: 0.94rem;
}

.profile-card > span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.profile-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.profile-grid span {
  background: #ffffff;
  border: 3px solid var(--line);
  border-radius: 6px;
  box-shadow: 2px 2px 0 var(--ink);
  display: grid;
  gap: 2px;
  padding: 8px;
}

.profile-grid b {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 1rem;
}

.profile-grid small {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 900;
  text-transform: uppercase;
}

.round-strip {
  justify-content: space-between;
  margin-bottom: 12px;
}

.timer-wrap {
  display: grid;
  justify-items: end;
  gap: 7px;
  min-width: 138px;
}

.timer-wrap.urgent #timerText {
  color: var(--bad);
  animation: timerPunch 0.45s steps(2, end) infinite;
}

.timer-wrap.urgent .timer-track {
  background: #ffe1dc;
}

.timer-wrap.urgent #timerFill {
  background: repeating-linear-gradient(
    90deg,
    var(--red) 0 10px,
    #ff9b8c 10px 18px
  );
}

#timerText {
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 1.2rem;
  font-weight: 950;
}

.timer-track {
  width: 138px;
  height: 13px;
  background: #ffffff;
  border: 3px solid var(--line);
  border-radius: 3px;
  overflow: hidden;
}

#timerFill {
  display: block;
  width: 0%;
  height: 100%;
  background: repeating-linear-gradient(
    90deg,
    var(--gold) 0 10px,
    #f6a53b 10px 18px
  );
  transition: width 0.2s steps(8, end);
}

.prompt-band {
  align-items: center;
  background: var(--ink);
  border: 3px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--soft-shadow);
  color: #ffffff;
  display: flex;
  font-size: clamp(1rem, 2vw, 1.42rem);
  font-weight: 950;
  justify-content: center;
  min-height: 52px;
  padding: 8px 12px;
  text-align: center;
}

body.drawer-mode .prompt-band {
  background: var(--mint);
  color: var(--ink);
  animation: promptReady 0.5s steps(4, end);
}

body[data-phase="judging"] .prompt-band {
  background: var(--gold);
  color: var(--ink);
}

body[data-phase="reveal"] .prompt-band,
body[data-phase="finished"] .prompt-band {
  background: var(--pink);
  color: var(--ink);
}

.canvas-wrap {
  position: relative;
  width: min(100%, clamp(280px, calc(100vh - 420px), 520px));
  margin: 12px auto 0;
  border: 4px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
  overflow: hidden;
  background:
    linear-gradient(90deg, rgba(16, 16, 20, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(16, 16, 20, 0.08) 1px, transparent 1px),
    #ffffff;
  background-size: 32px 32px;
  aspect-ratio: 1 / 1;
  transition: box-shadow 0.14s steps(2, end), transform 0.14s steps(2, end);
}

body.drawer-mode .canvas-wrap {
  box-shadow:
    var(--shadow),
    0 0 0 6px rgba(68, 215, 168, 0.45);
}

body[data-phase="judging"] .canvas-wrap {
  animation: judgingWobble 0.8s steps(2, end) infinite;
}

#drawingCanvas {
  display: block;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: none;
}

.canvas-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 10px;
  background:
    linear-gradient(90deg, rgba(16, 16, 20, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(16, 16, 20, 0.06) 1px, transparent 1px),
    rgba(255, 253, 245, 0.94);
  background-size: 16px 16px;
  color: var(--muted);
  text-align: center;
  padding: 20px;
}

.canvas-overlay strong {
  background: var(--gold);
  border: 3px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--soft-shadow);
  color: var(--ink);
  font-size: 1.35rem;
  padding: 8px 12px;
}

.canvas-overlay.hidden {
  display: none;
}

.tool-dock {
  background: var(--panel-2);
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-top: 10px;
  padding: 7px;
}

body.drawer-mode .tool-dock {
  background: #d9ffe7;
}

.swatches {
  display: flex;
  gap: 5px;
}

.swatch {
  width: 34px;
  background: var(--swatch);
  box-shadow: var(--soft-shadow);
}

.swatch.active {
  outline: 4px solid #ffffff;
  outline-offset: -8px;
}

.brush-preview {
  width: 36px;
  height: 36px;
  border: 3px solid var(--line);
  border-radius: 6px;
  background:
    linear-gradient(90deg, rgba(16, 16, 20, 0.08) 1px, transparent 1px),
    linear-gradient(180deg, rgba(16, 16, 20, 0.08) 1px, transparent 1px),
    #ffffff;
  background-size: 8px 8px;
  box-shadow: var(--soft-shadow);
  display: grid;
  place-items: center;
}

.brush-preview::after {
  content: "";
  width: var(--brush-size, 8px);
  height: var(--brush-size, 8px);
  background: var(--brush-color, var(--ink));
  border: 2px solid var(--line);
}

.size-slider {
  accent-color: var(--blue);
  width: 96px;
}

.result-panel {
  display: grid;
  grid-template-columns: 1fr auto auto;
  align-items: center;
  gap: 12px;
  background: #ffffff;
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
  margin-top: 16px;
  padding: 14px;
}

.result-panel:not([hidden]) {
  animation: panelIn 0.28s cubic-bezier(0.2, 1.5, 0.3, 1);
}

.result-panel[hidden] {
  display: none;
}

#judgeText {
  color: var(--muted);
  margin-top: 5px;
}

.score-badge {
  align-items: baseline;
  background: var(--gold);
  border: 3px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--soft-shadow);
  display: flex;
  gap: 4px;
  padding: 10px 14px;
}

.score-pulse .score-badge {
  animation: scoreBadgePop 0.6s steps(5, end);
}

.score-badge span {
  color: var(--ink);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 1.5rem;
  font-weight: 950;
}

.score-badge small {
  color: var(--ink);
  font-weight: 900;
}

.chat-log {
  align-content: start;
  background: #ffffff;
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--soft-shadow);
  display: grid;
  gap: 8px;
  height: 260px;
  overflow: auto;
  padding: 10px;
}

.chat-message {
  background: #fff6bf;
  border: 3px solid var(--line);
  border-radius: 6px;
  padding: 8px 10px;
}

.chat-message strong {
  display: block;
  font-size: 0.8rem;
  margin-bottom: 2px;
}

.chat-message span {
  color: #262b36;
  overflow-wrap: anywhere;
}

.chat-form {
  margin-top: 10px;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 20px;
  transform: translateX(-50%);
  background: var(--ink);
  border: 3px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  color: #ffffff;
  font-weight: 900;
  max-width: min(520px, calc(100vw - 32px));
  padding: 12px 16px;
  text-align: center;
  z-index: 10;
}

.settings-dialog {
  width: min(520px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  background: transparent;
}

.settings-dialog::backdrop {
  background: rgba(16, 16, 20, 0.45);
}

.settings-card {
  background: var(--panel);
  border: 4px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 10px;
  padding: 16px;
}

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

.settings-card .text-field {
  height: 42px;
}

.settings-status {
  color: var(--muted);
  font-family: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  font-size: 0.8rem;
  font-weight: 900;
}

.juice-layer {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 4;
}

.pixel-spark {
  position: absolute;
  width: 11px;
  height: 11px;
  background: var(--spark, var(--gold));
  border: 2px solid var(--line);
  box-shadow: 2px 2px 0 var(--ink);
  transform: translate(-50%, -50%);
  animation: pixelBurst 0.72s steps(6, end) forwards;
}

.pixel-spark.score-spark {
  width: 13px;
  height: 13px;
  animation-duration: 0.92s;
}

.round-pulse {
  animation: roundPulse 0.44s steps(4, end);
}

.score-pulse .result-panel:not([hidden]) {
  animation: scorePop 0.42s cubic-bezier(0.2, 1.6, 0.3, 1);
}

body.focus-mode .game-layout {
  grid-template-columns: 1fr;
}

body.focus-mode .setup-panel,
body.focus-mode .social-panel {
  display: none;
}

body.focus-mode .stage-panel {
  min-height: calc(100vh - 110px);
}

body.focus-mode .canvas-wrap {
  width: min(100%, calc(100vh - 250px), 760px);
}

@keyframes roundPulse {
  0% {
    box-shadow: 0 0 0 var(--ink), 0 0 0 0 var(--gold);
    transform: translate(0, 0);
  }
  45% {
    box-shadow: var(--shadow), 0 0 0 8px rgba(255, 209, 102, 0.75);
    transform: translate(-2px, -2px);
  }
  100% {
    box-shadow: var(--shadow), 0 0 0 0 rgba(255, 209, 102, 0);
    transform: translate(0, 0);
  }
}

@keyframes scorePop {
  0% {
    transform: scale(0.94);
  }
  65% {
    transform: scale(1.025);
  }
  100% {
    transform: scale(1);
  }
}

@keyframes panelIn {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.98);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes scoreBadgePop {
  0% {
    transform: rotate(-2deg) scale(1);
  }
  45% {
    transform: rotate(2deg) scale(1.12);
  }
  100% {
    transform: rotate(0deg) scale(1);
  }
}

@keyframes pixelBurst {
  0% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(calc(-50% + var(--x)), calc(-50% + var(--y))) rotate(180deg) scale(0.35);
  }
}

@keyframes promptReady {
  0% {
    transform: translateY(-2px);
  }
  100% {
    transform: translateY(0);
  }
}

@keyframes judgingWobble {
  0%,
  100% {
    transform: translate(0, 0);
  }
  50% {
    transform: translate(1px, -1px);
  }
}

@keyframes timerPunch {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

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

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

  .canvas-wrap {
    width: min(100%, 560px);
  }

  .social-panel {
    order: 3;
  }
}

@media (max-width: 700px) {
  .shell {
    width: min(100vw - 20px, 1480px);
    padding: 12px 0;
  }

  .topbar,
  .round-strip,
  .identity-strip,
  .result-panel {
    align-items: stretch;
    flex-direction: column;
  }

  .topbar {
    display: grid;
  }

  h1 {
    font-size: 2.45rem;
  }

  .identity-strip {
    display: grid;
    grid-template-columns: 1fr;
  }

  .stage-panel {
    padding: 10px;
  }

  .prompt-band {
    min-height: 44px;
    font-size: 1rem;
  }

  .canvas-wrap {
    width: min(100%, calc(100vh - 330px));
    min-width: 0;
  }

  .tool-dock {
    position: sticky;
    bottom: 8px;
    z-index: 6;
  }

  .swatch,
  .brush-preview {
    width: 42px;
    min-height: 42px;
  }

  .size-slider {
    width: min(180px, 48vw);
  }

  .result-panel {
    grid-template-columns: 1fr;
  }

  .timer-wrap {
    justify-items: stretch;
  }

  .timer-track {
    width: 100%;
  }

  .room-row,
  .settings-block {
    align-items: stretch;
    flex-direction: column;
  }

  .button,
  .tool-button,
  .text-field {
    min-height: 46px;
  }

  body.focus-mode .shell {
    width: min(100vw - 12px, 1480px);
    padding-top: 6px;
  }

  body.focus-mode .topbar {
    margin-bottom: 6px;
  }

  body.focus-mode h1 {
    font-size: 1.7rem;
  }

  body.focus-mode .canvas-wrap {
    width: min(100%, calc(100vh - 260px));
  }
}
