:root {
  --bg: #e8eef4;
  --bg-deep: #d5e0ea;
  --surface: #ffffff;
  --ink: #0f172a;
  --ink-soft: #475569;
  --line: #c8d4e0;
  --accent: #0d9488;
  --accent-ink: #ffffff;
  --mine: #ccfbf1;
  --theirs: #ffffff;
  --danger: #b91c1c;
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --header-h: 64px;
  --composer-h: 72px;
  --font: "DM Sans", system-ui, sans-serif;
  --shadow: 0 10px 30px rgba(15, 23, 42, 0.08);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

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

body {
  font-family: var(--font);
  color: var(--ink);
  background:
    radial-gradient(1200px 600px at 10% -10%, #b8e6df 0%, transparent 55%),
    radial-gradient(900px 500px at 100% 0%, #c7d7f0 0%, transparent 50%),
    var(--bg);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  height: 100%;
  max-width: 520px;
  margin: 0 auto;
  position: relative;
  background: transparent;
}

.screen {
  height: 100%;
  display: flex;
  flex-direction: column;
}

.screen[hidden] {
  display: none !important;
}

/* Setup */
.setup-screen {
  align-items: center;
  justify-content: center;
  padding: calc(24px + var(--safe-top)) 20px calc(24px + var(--safe-bottom));
}

.setup-panel {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px 22px;
  box-shadow: var(--shadow);
}

.brand,
.brand-sm {
  margin: 0;
  font-weight: 700;
  letter-spacing: -0.03em;
  color: var(--accent);
}

.brand {
  font-size: 1.35rem;
}

.brand-sm {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.sync-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 2px 7px;
  border-radius: 999px;
  font-size: 0.65rem;
  letter-spacing: 0.04em;
  vertical-align: middle;
  background: #e2e8f0;
  color: #475569;
  text-transform: uppercase;
}

.sync-badge[data-mode="shared"] {
  background: #ccfbf1;
  color: #0f766e;
}

.setup-panel code {
  font-family: ui-monospace, Consolas, monospace;
  font-size: 0.9em;
  background: #f1f5f9;
  padding: 1px 5px;
  border-radius: 6px;
}

.setup-panel h1 {
  margin: 8px 0 6px;
  font-size: 1.75rem;
  letter-spacing: -0.03em;
}

.setup-sub,
.hint {
  color: var(--ink-soft);
  line-height: 1.45;
  margin: 0 0 20px;
  font-size: 0.95rem;
}

.hint {
  margin: 16px 0 0;
  font-size: 0.8rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.field input,
.composer textarea {
  font: inherit;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
  padding: 12px 14px;
  outline: none;
  width: 100%;
}

.field input:focus,
.composer textarea:focus {
  border-color: var(--accent);
  background: #fff;
}

.btn {
  font: inherit;
  font-weight: 600;
  border: none;
  border-radius: 12px;
  padding: 12px 16px;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}

.btn.primary {
  background: var(--accent);
  color: var(--accent-ink);
  width: 100%;
}

.btn.primary.compact,
.btn.ghost.compact {
  width: auto;
  padding: 8px 12px;
  font-size: 0.9rem;
}

.btn.ghost {
  background: transparent;
  color: var(--ink-soft);
}

.btn:active {
  transform: scale(0.98);
}

.icon-btn {
  width: 42px;
  height: 42px;
  border: none;
  border-radius: 12px;
  background: transparent;
  color: var(--ink);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.icon-btn:active {
  background: rgba(15, 23, 42, 0.06);
}

/* Chat */
.chat-screen {
  background: rgba(255, 255, 255, 0.55);
  backdrop-filter: blur(8px);
  border-left: 1px solid transparent;
  border-right: 1px solid transparent;
}

.chat-header {
  flex: 0 0 auto;
  min-height: calc(var(--header-h) + var(--safe-top));
  padding: var(--safe-top) 10px 8px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.9);
}

.header-text h1 {
  margin: 2px 0 0;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  gap: 2px;
}

.room-tabs {
  display: flex;
  gap: 6px;
  padding: 8px 12px 0;
  background: rgba(255, 255, 255, 0.9);
  border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}

.room-tab {
  font: inherit;
  font-weight: 600;
  font-size: 0.9rem;
  border: none;
  background: transparent;
  color: var(--ink-soft);
  padding: 8px 14px 10px;
  border-radius: 10px 10px 0 0;
  cursor: pointer;
}

.room-tab.active {
  color: var(--ink);
  background: #f8fafc;
  box-shadow: inset 0 -2px 0 var(--accent);
}

.room-panel {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.room-panel[hidden] {
  display: none !important;
}

.message-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px 14px calc(12px + var(--composer-h) + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

/* Shared whiteboard */
.board-status {
  padding: 10px 14px 6px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.board-status-text {
  margin: 0;
  font-weight: 600;
  font-size: 0.9rem;
  color: var(--ink-soft);
}

.board-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  flex-wrap: wrap;
}

.board-tools {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  align-items: center;
}

.board-tool {
  font: inherit;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid var(--line);
  background: #f8fafc;
  color: var(--ink-soft);
  border-radius: 8px;
  padding: 6px 10px;
  cursor: pointer;
}

.board-tool.active {
  background: #0f172a;
  border-color: #0f172a;
  color: #fff;
}

.board-swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
}

.board-swatch {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid rgba(15, 23, 42, 0.18);
  background: var(--swatch, #0f172a);
  padding: 0;
  cursor: pointer;
}

.board-swatch.selected {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.board-swatch.mine-color {
  box-shadow: inset 0 0 0 1px #fff;
}

.board-swatch.taken {
  opacity: 0.28;
  cursor: not-allowed;
}

.board-layer-name {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.board-layer-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex: 0 0 auto;
  border: 1px solid rgba(15, 23, 42, 0.2);
}

.board-canvas-wrap {
  flex: 1;
  min-height: 200px;
  padding: 10px 12px 0;
  display: grid;
}

#board-bg,
#board-mine {
  grid-area: 1 / 1;
  width: 100%;
  height: 100%;
  display: block;
  border: 1px solid var(--line);
  border-radius: 14px;
  touch-action: none;
  box-shadow: var(--shadow);
}

#board-bg {
  background: #fff;
  pointer-events: none;
  z-index: 0;
}

#board-mine {
  background: transparent;
  z-index: 1;
}

.board-layers {
  margin: 8px 12px 12px;
  max-height: 96px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px 10px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.board-layer-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink);
  margin-bottom: 4px;
}

.board-layer-row.mine {
  font-weight: 600;
  color: #0f766e;
}

/* Pictionary */
.pic-status {
  padding: 10px 14px 6px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.92);
}

.pic-status-text {
  margin: 0;
  font-weight: 600;
  font-size: 0.92rem;
}

.pic-word-line {
  margin: 4px 0 0;
  font-size: 1.05rem;
  letter-spacing: 0.08em;
  color: var(--accent);
  font-weight: 700;
}

.pic-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  background: #fff;
  flex-wrap: wrap;
}

.pic-canvas-wrap {
  flex: 1;
  min-height: 180px;
  padding: 10px 12px 0;
}

#pic-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  touch-action: none;
  box-shadow: var(--shadow);
}

.pic-side {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  padding: 8px 12px;
  max-height: 120px;
}

.pic-scores,
.pic-guesses {
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  padding: 8px;
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.pic-score-row {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--ink);
  margin-bottom: 4px;
}

.pic-guess {
  margin-bottom: 4px;
  color: var(--ink);
}

.pic-guess.correct {
  color: #0f766e;
  font-weight: 600;
}

.pic-composer {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px calc(10px + var(--safe-bottom));
  border-top: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.95);
}

.pic-composer input {
  flex: 1;
  font: inherit;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #f8fafc;
  padding: 12px 14px;
  outline: none;
  min-width: 0;
}

.pic-composer input:focus {
  border-color: var(--accent);
  background: #fff;
}

.msg {
  max-width: 82%;
  display: flex;
  flex-direction: column;
  gap: 4px;
  animation: rise 0.22s ease-out;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.msg.mine {
  align-self: flex-end;
}

.msg.theirs {
  align-self: flex-start;
}

.msg-meta {
  font-size: 0.72rem;
  color: var(--ink-soft);
  padding: 0 6px;
}

.bubble {
  border-radius: 16px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  background: var(--theirs);
  box-shadow: 0 1px 0 rgba(15, 23, 42, 0.04);
  word-break: break-word;
  white-space: pre-wrap;
  line-height: 1.4;
}

.msg.mine .bubble {
  background: var(--mine);
  border-color: #99f6e4;
}

.bubble img.drawing {
  display: block;
  max-width: 100%;
  width: 240px;
  border-radius: 10px;
  background: #fff;
  touch-action: manipulation;
}

.bubble.drawing-only {
  padding: 6px;
}

.empty-state {
  margin: auto;
  text-align: center;
  color: var(--ink-soft);
  padding: 24px;
  max-width: 260px;
}

.empty-state strong {
  display: block;
  color: var(--ink);
  margin-bottom: 6px;
  font-size: 1.05rem;
}

.composer {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  min-height: calc(var(--composer-h) + var(--safe-bottom));
  padding: 10px 10px calc(10px + var(--safe-bottom));
  display: flex;
  align-items: flex-end;
  gap: 8px;
  background: rgba(255, 255, 255, 0.95);
  border-top: 1px solid var(--line);
}

.composer textarea {
  resize: none;
  min-height: 44px;
  max-height: 120px;
  line-height: 1.35;
  padding-top: 12px;
}

.send-btn {
  width: 44px;
  height: 44px;
  padding: 0;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  flex: 0 0 auto;
}

.composer-tool {
  flex: 0 0 auto;
  background: #f1f5f9;
}

.composer-tool.recording {
  background: #fecaca;
  color: var(--danger);
  animation: pulse-rec 1s ease-in-out infinite;
}

@keyframes pulse-rec {
  50% {
    transform: scale(1.06);
  }
}

.rec-banner {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: calc(var(--composer-h) + var(--safe-bottom) + 8px);
  background: #7f1d1d;
  color: #fff;
  text-align: center;
  font-size: 0.85rem;
  font-weight: 600;
  padding: 8px 12px;
  border-radius: 10px;
  pointer-events: none;
  z-index: 5;
}

.audio-bubble {
  padding: 8px 10px;
  min-width: 200px;
}

.audio-bubble audio {
  width: 100%;
  height: 36px;
}

.bubble canvas.drawing {
  display: block;
  max-width: 100%;
  width: 240px;
  height: auto;
  border-radius: 10px;
  background: #fff;
}

/* Draw screen */
.draw-screen {
  position: absolute;
  inset: 0;
  z-index: 20;
  background: #f8fafc;
}

.draw-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(10px + var(--safe-top)) 12px 8px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.draw-title {
  margin: 0;
  font-weight: 700;
}

.draw-toolbar {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.tool-group {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--ink-soft);
}

.tool-group input[type="color"] {
  width: 36px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: none;
  padding: 0;
}

.tool-group input[type="range"] {
  width: 90px;
}

.canvas-wrap {
  flex: 1;
  min-height: 0;
  padding: 12px;
  padding-bottom: calc(12px + var(--safe-bottom));
}

#draw-canvas {
  width: 100%;
  height: 100%;
  display: block;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 16px;
  touch-action: none;
  box-shadow: var(--shadow);
}

@media (min-width: 540px) {
  #app {
    border-left: 1px solid var(--line);
    border-right: 1px solid var(--line);
    box-shadow: var(--shadow);
    background: rgba(255, 255, 255, 0.35);
  }
}
