:root {
  color-scheme: light;
  --ink: #1f2937;
  --muted: #64748b;
  --paper: #fff7df;
  --paper-2: #e9f7f5;
  --surface: #ffffff;
  --line: #e7ddc5;
  --blue: #23395d;
  --blue-soft: #dce8ff;
  --coral: #ff8066;
  --coral-dark: #d85f49;
  --mint: #47b8a7;
  --mint-dark: #248577;
  --sun: #ffd166;
  --shadow: 0 18px 44px rgba(31, 41, 55, 0.14);
}

* {
  box-sizing: border-box;
}

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

body {
  background:
    linear-gradient(135deg, rgba(255, 209, 102, 0.34), transparent 30%),
    linear-gradient(315deg, rgba(71, 184, 167, 0.24), transparent 38%),
    var(--paper);
  color: var(--ink);
  font-family: Inter, "PingFang SC", "Microsoft YaHei", Arial, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  cursor: pointer;
}

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

.game-shell {
  display: grid;
  gap: 18px;
  margin: 0 auto;
  max-width: 1440px;
  min-height: 100vh;
  padding: clamp(16px, 2vw, 28px);
}

.lobby-screen {
  align-items: center;
  display: grid;
  min-height: calc(100vh - 56px);
}

.lobby-screen.is-hidden,
.game-screen {
  display: none;
}

.game-screen.is-active {
  display: grid;
  gap: 18px;
}

.lobby-window {
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(255, 255, 255, 0.82)),
    var(--surface);
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 28px;
  box-shadow: 0 28px 70px rgba(31, 41, 55, 0.18);
  display: grid;
  gap: 24px;
  grid-template-columns: minmax(0, 0.95fr) minmax(360px, 1.05fr);
  overflow: hidden;
  padding: clamp(24px, 4vw, 52px);
}

.lobby-hero {
  align-content: center;
  display: grid;
  gap: 14px;
}

.app-mark.large {
  font-size: 2.4rem;
  height: 88px;
  width: 88px;
}

.lobby-subtitle {
  color: var(--muted);
  font-size: 1.05rem;
  font-weight: 800;
  line-height: 1.7;
  margin: 0;
  max-width: 520px;
}

.mode-cards {
  display: grid;
  gap: 16px;
}

.mode-card {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 22px;
  box-shadow: 0 14px 30px rgba(31, 41, 55, 0.10);
  color: var(--ink);
  display: grid;
  gap: 9px;
  padding: 22px;
  text-align: left;
}

button.mode-card {
  border-color: rgba(255, 128, 102, 0.30);
}

.mode-card span {
  color: var(--mint-dark);
  font-size: 0.78rem;
  font-weight: 900;
}

.mode-card strong {
  font-size: 1.55rem;
  line-height: 1.15;
}

.mode-card small {
  color: var(--muted);
  font-size: 0.92rem;
  font-weight: 800;
  line-height: 1.55;
}

.is-local {
  background:
    linear-gradient(135deg, rgba(255, 128, 102, 0.16), transparent),
    #ffffff;
}

.room-actions {
  display: grid;
  gap: 10px;
  margin-top: 6px;
}

.join-row {
  display: grid;
  gap: 10px;
  grid-template-columns: minmax(0, 1fr) auto;
}

.join-row input {
  border: 1px solid var(--line);
  border-radius: 14px;
  color: var(--blue);
  font-weight: 900;
  min-height: 48px;
  padding: 0 14px;
  text-transform: uppercase;
}

.room-code,
.lobby-status {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 900;
  margin: 0;
}

.lobby-status {
  background: var(--paper-2);
  border: 1px solid rgba(71, 184, 167, 0.18);
  border-radius: 16px;
  grid-column: 1 / -1;
  padding: 14px 16px;
}

.game-header {
  align-items: center;
  display: flex;
  gap: 18px;
  justify-content: space-between;
}

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

.app-mark {
  align-items: center;
  background: var(--blue);
  border: 3px solid rgba(255, 255, 255, 0.8);
  border-radius: 18px;
  box-shadow: 0 10px 24px rgba(35, 57, 93, 0.22);
  color: #ffffff;
  display: grid;
  font-size: 1.45rem;
  font-weight: 900;
  height: 62px;
  justify-content: center;
  width: 62px;
}

.eyebrow,
.card-kicker,
.info-card span {
  color: var(--mint-dark);
  font-size: 0.78rem;
  font-weight: 900;
  letter-spacing: 0;
  margin: 0;
}

h1 {
  font-size: clamp(2.25rem, 5vw, 4.8rem);
  line-height: 0.95;
  margin: 4px 0 0;
}

h2 {
  font-size: clamp(1.25rem, 2vw, 1.7rem);
  line-height: 1.15;
  margin: 4px 0 0;
}

.mode-switch,
.segmented {
  background: rgba(255, 255, 255, 0.75);
  border: 1px solid var(--line);
  border-radius: 999px;
  display: inline-grid;
  grid-auto-flow: column;
  gap: 4px;
  padding: 5px;
}

.header-actions {
  align-items: center;
  display: flex;
  gap: 10px;
}

.compact-button {
  min-height: 42px;
}

.mode-button,
.segment {
  background: transparent;
  border: 0;
  border-radius: 999px;
  color: var(--muted);
  font-weight: 900;
  min-height: 42px;
  padding: 0 18px;
}

.mode-button.is-active,
.segment.is-active {
  background: var(--blue);
  color: #ffffff;
}

.info-strip {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.info-card,
.play-card {
  background: rgba(255, 255, 255, 0.88);
  border: 1px solid rgba(231, 221, 197, 0.92);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.info-card {
  display: grid;
  gap: 4px;
  min-height: 82px;
  padding: 16px 18px;
}

.info-card strong {
  font-size: 1.35rem;
  line-height: 1.1;
}

.info-card small {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 800;
}

.stage {
  display: none;
  gap: 18px;
  grid-template-columns: minmax(0, 1fr) 310px;
  min-height: 0;
}

.stage.is-active {
  display: grid;
}

.play-card {
  overflow: hidden;
}

.canvas-card {
  display: grid;
  gap: 16px;
  padding: clamp(16px, 2vw, 24px);
}

.tool-card,
.score-card {
  align-content: start;
  display: grid;
  gap: 16px;
  padding: 20px;
}

.card-head {
  align-items: center;
  display: flex;
  gap: 16px;
  justify-content: space-between;
}

.card-head.compact {
  align-items: start;
}

.primary-button,
.secondary-button {
  border-radius: 14px;
  min-height: 48px;
  padding: 0 18px;
}

.primary-button {
  background: var(--coral);
  border: 1px solid var(--coral-dark);
  box-shadow: 0 10px 22px rgba(255, 128, 102, 0.24);
  color: #ffffff;
  font-weight: 900;
}

.primary-button:hover {
  background: var(--coral-dark);
}

.secondary-button {
  background: #ffffff;
  border: 1px solid var(--line);
  color: var(--blue);
  font-weight: 900;
}

.wide-button {
  width: 100%;
}

.canvas-frame,
.puzzle-frame {
  background:
    linear-gradient(90deg, rgba(35, 57, 93, 0.045) 1px, transparent 1px),
    linear-gradient(rgba(35, 57, 93, 0.045) 1px, transparent 1px),
    #ffffff;
  background-size: 28px 28px;
  border: 2px solid #ffffff;
  border-radius: 18px;
  box-shadow:
    inset 0 0 0 1px rgba(35, 57, 93, 0.08),
    0 18px 34px rgba(31, 41, 55, 0.10);
  overflow: hidden;
}

.canvas-frame {
  aspect-ratio: 4 / 3;
  line-height: 0;
  width: min(100%, calc((100vh - 250px) * 4 / 3), 1060px);
}

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

.puzzle-frame {
  aspect-ratio: auto;
  display: grid;
  padding: 14px;
  width: min(100%, calc((100vh - 250px) * 4 / 3), 1060px);
}

.puzzle-layout {
  display: grid;
  gap: 14px;
  grid-template-rows: minmax(0, 1fr) auto;
}

.target-zone,
.tray-zone {
  border-radius: 16px;
  display: grid;
  gap: 10px;
  padding: 12px;
}

.target-zone {
  background: #dce8ff;
  border: 1px solid rgba(35, 57, 93, 0.14);
}

.tray-zone {
  background: rgba(255, 240, 194, 0.78);
  border: 1px solid rgba(255, 209, 102, 0.62);
  min-height: 72px;
}

.zone-title {
  align-items: baseline;
  display: flex;
  gap: 10px;
  justify-content: space-between;
}

.zone-title strong {
  color: var(--blue);
  font-size: 0.95rem;
}

.zone-title span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
}

.puzzle-board {
  aspect-ratio: 4 / 3;
  background: rgba(255, 255, 255, 0.56);
  border: 2px dashed rgba(35, 57, 93, 0.28);
  border-radius: 14px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  grid-template-rows: repeat(3, 1fr);
  min-height: 0;
  overflow: hidden;
  user-select: none;
}

.target-slot {
  align-items: center;
  background: rgba(255, 255, 255, 0.58);
  border: 1px dashed rgba(35, 57, 93, 0.22);
  display: grid;
  justify-items: center;
  min-height: 0;
  position: relative;
}

.target-slot > span {
  color: rgba(35, 57, 93, 0.28);
  font-size: 1.2rem;
  font-weight: 900;
}

.piece-tray {
  inset: 0;
  pointer-events: none;
  position: fixed;
  z-index: 20;
}

.piece {
  background-repeat: no-repeat;
  border: 2px solid rgba(255, 255, 255, 0.98);
  border-radius: 10px;
  box-shadow: 0 10px 18px rgba(31, 41, 55, 0.14);
  min-height: 0;
  overflow: hidden;
  position: relative;
  touch-action: none;
}

.target-slot .piece {
  border-radius: 0;
  box-shadow: none;
  height: 100%;
  width: 100%;
}

.piece-tray .piece {
  cursor: grab;
  pointer-events: auto;
  position: fixed;
}

.piece-tray .piece.is-dragging {
  cursor: grabbing;
  transform: rotate(1deg) scale(1.04);
  z-index: 30;
}

.piece::after {
  border: 0 solid var(--sun);
  content: "";
  inset: 0;
  pointer-events: none;
  position: absolute;
  transition: border-width 120ms ease;
}

.piece.is-selected::after,
.piece:focus-visible::after {
  border-width: 6px;
}

.piece.is-locked {
  cursor: default;
}

.piece-button {
  background: transparent;
  border: 0;
  display: block;
  height: 100%;
  padding: 0;
  width: 100%;
}

.piece-button:focus {
  outline: 0;
}

.tool-row {
  display: grid;
  gap: 8px;
}

.field-label {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

input[type="color"] {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 14px;
  height: 52px;
  padding: 5px;
  width: 100%;
}

input[type="range"] {
  accent-color: var(--coral);
  width: 100%;
}

output {
  color: var(--muted);
  font-size: 0.82rem;
  font-weight: 900;
}

.action-grid,
.score-grid {
  display: grid;
  gap: 10px;
  grid-template-columns: 1fr 1fr;
}

.hint-box {
  background: var(--paper-2);
  border: 1px solid rgba(71, 184, 167, 0.20);
  border-radius: 16px;
  color: var(--mint-dark);
  display: grid;
  gap: 6px;
  padding: 14px;
}

.hint-box strong {
  color: var(--ink);
}

.hint-box span {
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 800;
  line-height: 1.55;
}

.score-tile {
  background: var(--blue-soft);
  border: 1px solid rgba(35, 57, 93, 0.12);
  border-radius: 16px;
  display: grid;
  gap: 6px;
  padding: 14px;
}

.score-tile span {
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 900;
}

.score-tile strong {
  color: var(--blue);
  font-size: 1.75rem;
  line-height: 1;
}

.result-text {
  background: #fff2cb;
  border: 1px solid rgba(255, 209, 102, 0.55);
  border-radius: 16px;
  color: #8a6210;
  font-weight: 900;
  margin: 0;
  min-height: 52px;
  padding: 15px;
}

@media (max-width: 1020px) {
  .lobby-window {
    grid-template-columns: 1fr;
  }

  .stage,
  .stage.is-active {
    grid-template-columns: 1fr;
  }

  .tool-card,
  .score-card {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .card-head.compact,
  .hint-box,
  .wide-button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 680px) {
  .lobby-window {
    border-radius: 22px;
    padding: 20px;
  }

  .join-row {
    grid-template-columns: 1fr;
  }

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

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

  .mode-switch {
    width: 100%;
  }

  .mode-button {
    width: 100%;
  }

  .info-strip,
  .tool-card,
  .score-card {
    grid-template-columns: 1fr;
  }

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

  .canvas-frame,
  .puzzle-frame {
    width: 100%;
  }

  .piece-tray {
    grid-template-columns: repeat(4, minmax(54px, 1fr));
  }
}
