:root {
  --ink: #1a1410;
  --ink-soft: #4a3f36;
  --paper: #f3ebe0;
  --sand: #e4d4c0;
  --ochre: #d4a017;
  --terracotta: #c45c26;
  --teal: #1f6f5b;
  --white: #fffaf3;
  --shadow: 0 16px 40px rgba(26, 20, 16, 0.18);
  --radius: 16px;
  --font-display: "Fraunces", Georgia, serif;
  --font-body: "DM Sans", sans-serif;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --tap: 44px;
}

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

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

body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper);
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left);
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  background:
    radial-gradient(900px 500px at 8% -5%, rgba(212, 160, 23, 0.28), transparent 55%),
    radial-gradient(700px 420px at 95% 10%, rgba(196, 92, 38, 0.2), transparent 50%),
    linear-gradient(160deg, #f6efe6 0%, #e8d9c6 48%, #dcc9b2 100%);
}

.atmosphere::after {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.07;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 200 200' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
  pointer-events: none;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem clamp(0.85rem, 3vw, 1.25rem);
}

.ghost {
  border: 0;
  background: transparent;
  color: var(--ink-soft);
  font: 600 0.75rem/1 var(--font-body);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  cursor: pointer;
  min-height: var(--tap);
  padding: 0.5rem 0.4rem;
}

.view {
  display: none;
  min-height: calc(100dvh - 4rem);
  padding: 0 clamp(0.85rem, 3vw, 1.25rem) clamp(1.25rem, 4vw, 2.5rem);
}

.view.active {
  display: block;
  animation: rise 0.4s ease both;
}

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

.hero {
  max-width: 40rem;
  margin: clamp(2rem, 10vh, 11vh) auto 0;
}

.brand {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: clamp(3.2rem, 12vw, 5.6rem);
  line-height: 0.9;
  letter-spacing: -0.03em;
  margin: 0 0 1rem;
  color: var(--ink);
}

.brand.sm {
  font-size: 1.35rem;
  margin-bottom: 0.35rem;
}

h1,
h2,
h3 {
  font-family: var(--font-display);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 0.75rem;
}

h1 {
  font-size: clamp(1.45rem, 4.5vw, 2.1rem);
  max-width: 14ch;
}

.lede {
  color: var(--ink-soft);
  font-size: 1.05rem;
  line-height: 1.5;
  max-width: 34ch;
  margin: 0 0 1.5rem;
}

.hint,
.meta {
  color: var(--ink-soft);
  font-size: 0.9rem;
}

.cta-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin: 1.1rem 0;
}

.cta-row .btn {
  flex: 1 1 11rem;
}

.btn {
  border: 0;
  border-radius: 999px;
  padding: 0.9rem 1.3rem;
  min-height: var(--tap);
  font: 600 0.95rem/1 var(--font-body);
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.btn.primary {
  background: var(--ink);
  color: var(--white);
  box-shadow: var(--shadow);
}

.btn.secondary {
  background: var(--ochre);
  color: var(--ink);
}

.btn.ghost-btn {
  background: rgba(255, 250, 243, 0.55);
  color: var(--ink);
  border: 1px solid rgba(26, 20, 16, 0.12);
}

.btn.sm {
  padding: 0.55rem 0.85rem;
  font-size: 0.85rem;
}

.btn.danger {
  color: #7a2410;
  border-color: rgba(196, 92, 38, 0.35);
  background: rgba(196, 92, 38, 0.12);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

@media (hover: hover) and (pointer: fine) {
  .btn:hover {
    transform: translateY(-1px);
  }
}

.panel {
  width: min(100%, 28rem);
  margin: clamp(1.25rem, 5vh, 5vh) auto 0;
  padding: clamp(1.15rem, 3vw, 1.7rem);
  background: rgba(255, 250, 243, 0.8);
  border: 1px solid rgba(26, 20, 16, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(10px);
}

.panel.center {
  text-align: center;
}

.lobby-layout {
  display: grid;
  gap: 1rem;
  max-width: 56rem;
  margin: 0 auto;
}

@media (min-width: 860px) {
  .lobby-layout {
    grid-template-columns: 1.15fr 0.95fr;
    align-items: start;
    margin-top: 3vh;
  }

  .lobby-layout .panel {
    margin-top: 0;
    width: 100%;
  }
}

.field {
  display: grid;
  gap: 0.35rem;
  margin: 0.85rem 0;
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.field.inline {
  grid-template-columns: 1fr auto;
  align-items: center;
}

.field input,
.field select,
#chat-form input {
  border: 1px solid rgba(26, 20, 16, 0.15);
  border-radius: 12px;
  padding: 0.75rem 0.9rem;
  font: 500 16px/1.2 var(--font-body);
  background: var(--white);
  color: var(--ink);
  width: 100%;
}

.field.inline input {
  width: 5.5rem;
}

.field-label {
  font-size: 0.85rem;
  color: var(--ink-soft);
}

.avatar-pick {
  margin: 1rem 0;
}

.swatches {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  margin-top: 0.45rem;
}

.swatch {
  width: 2rem;
  height: 2rem;
  border-radius: 999px;
  border: 2px solid transparent;
  cursor: pointer;
}

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

.code {
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  border: 0;
  background: var(--ochre);
  color: var(--ink);
  border-radius: 12px;
  padding: 0.15rem 0.5rem;
  cursor: pointer;
  vertical-align: baseline;
}

.player-list,
.scores,
.podium {
  list-style: none;
  margin: 1rem 0;
  padding: 0;
  display: grid;
  gap: 0.4rem;
}

.player-list li,
.scores li,
.podium li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.65rem;
  padding: 0.6rem 0.75rem;
  border-radius: 12px;
  background: rgba(26, 20, 16, 0.045);
  font-weight: 500;
  min-width: 0;
}

.player-left {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  min-width: 0;
}

.avatar-dot {
  width: 1.65rem;
  height: 1.65rem;
  border-radius: 999px;
  flex: 0 0 auto;
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12);
}

.name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tag {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-soft);
}

.subhead {
  margin-top: 1rem;
  font-size: 1.05rem;
}

.error {
  color: var(--terracotta);
  font-weight: 600;
}

/* —— Game —— */
.game-view {
  min-height: 0 !important;
  height: calc(100dvh - 3.25rem - var(--safe-top) - var(--safe-bottom));
  padding: 0 clamp(0.4rem, 1vw, 0.75rem) 0.35rem !important;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
}

body:has(.game-view.active) {
  overflow: hidden;
}

body:has(.game-view.active) .topbar {
  padding-top: 0.4rem;
  padding-bottom: 0.35rem;
}

.game-view .word-bar {
  flex: 0 0 auto;
  text-align: center;
  margin: 0;
}

.game-shell {
  display: grid;
  grid-template-columns: 15rem minmax(0, 1fr) 16rem;
  grid-template-rows: minmax(0, 1fr);
  align-items: stretch;
  gap: 0.85rem;
  width: 100%;
  max-width: none;
  flex: 1 1 auto;
  min-height: 0;
  margin: 0;
}

.scoreboard-panel,
.chat-panel {
  background: rgba(255, 250, 243, 0.82);
  border: 1px solid rgba(26, 20, 16, 0.08);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 0.85rem;
  width: 100%;
  height: 100%;
  min-height: 0;
  max-height: none;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  align-self: stretch;
}

.scoreboard-panel .scores {
  flex: 0 1 auto;
  max-height: 100%;
  min-height: 0;
  overflow: auto;
  margin: 0.5rem 0;
  align-content: start;
  align-items: stretch;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
}

.scoreboard-panel .scores li {
  flex: 0 0 auto;
  height: auto;
  min-height: 0;
  padding: 0.55rem 0.7rem;
}

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

.chat-panel .chat-log {
  flex: 1 1 auto;
  min-height: 0;
}

.ghost.danger-text {
  color: #8a2a1a;
  margin-left: auto;
}

.score-head {
  display: grid;
  gap: 0.3rem;
  margin-bottom: 0.45rem;
  padding-bottom: 0.45rem;
  border-bottom: 1px solid rgba(26, 20, 16, 0.08);
  flex: 0 0 auto;
}

.round-label {
  margin: 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
  font-weight: 600;
}

.timer {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.55rem;
  min-height: var(--tap);
  display: grid;
  place-items: center;
  background: var(--ink);
  color: var(--ochre);
  border-radius: 14px;
  font-variant-numeric: tabular-nums;
}

.scores li.is-drawer {
  background: rgba(212, 160, 23, 0.22);
}

.scores li.is-guessed {
  outline: 2px solid var(--teal);
}

.scores li.is-you {
  box-shadow: inset 0 0 0 1px rgba(31, 111, 91, 0.45);
}

.score-actions {
  display: flex;
  gap: 0.25rem;
}

.score-actions button {
  border: 0;
  background: rgba(26, 20, 16, 0.06);
  border-radius: 8px;
  font-size: 0.68rem;
  padding: 0.25rem 0.4rem;
  cursor: pointer;
  color: var(--ink-soft);
}

.stage {
  min-width: 0;
  min-height: 0;
  height: 100%;
  align-self: stretch;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.scoreboard-panel #btn-abort {
  margin-top: auto;
  flex: 0 0 auto;
}

.word-display {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.05rem, 2.2vw, 1.45rem);
  font-weight: 700;
  letter-spacing: 0.08em;
  min-height: 1.25em;
}

.phase-hint {
  margin: 0.15rem 0 0;
  color: var(--ink-soft);
  font-size: 0.85rem;
}

.canvas-wrap {
  position: relative;
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  aspect-ratio: auto;
  background: #fff;
  border-radius: 14px;
  border: 1px solid rgba(26, 20, 16, 0.12);
  box-shadow: var(--shadow);
  overflow: hidden;
  touch-action: none;
}

#canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: crosshair;
}

.choose-overlay,
.reveal-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  gap: 0.85rem;
  padding: 1rem;
  background: rgba(26, 20, 16, 0.72);
  color: var(--white);
  text-align: center;
  z-index: 3;
}

.word-choices {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.55rem;
}

.word-choices button {
  border: 0;
  border-radius: 999px;
  padding: 0.75rem 1.1rem;
  min-height: var(--tap);
  font: 600 1rem/1 var(--font-body);
  background: var(--ochre);
  color: var(--ink);
  cursor: pointer;
}

.reveal-word {
  font-family: var(--font-display);
  font-size: clamp(1.6rem, 5vw, 2.4rem);
  font-weight: 800;
  margin: 0;
}

.reveal-scores {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.35rem;
}

.toolbar {
  margin-top: 0.4rem;
  padding: 0.45rem 0.55rem;
  border-radius: 14px;
  background: rgba(255, 250, 243, 0.85);
  border: 1px solid rgba(26, 20, 16, 0.08);
  flex: 0 0 auto;
}

.tool-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-bottom: 0.45rem;
}

.tool-row.colors {
  gap: 0.35rem;
}

.color-btn {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 6px;
  border: 2px solid rgba(26, 20, 16, 0.15);
  cursor: pointer;
  padding: 0;
}

.color-btn.active-a {
  outline: 2px solid var(--ink);
  outline-offset: 1px;
}

.color-btn.active-b {
  box-shadow: inset 0 0 0 2px var(--white), 0 0 0 2px var(--terracotta);
}

.tool {
  border: 1px solid rgba(26, 20, 16, 0.12);
  background: var(--white);
  border-radius: 999px;
  padding: 0.45rem 0.75rem;
  min-height: 2.4rem;
  font: 600 0.8rem/1 var(--font-body);
  cursor: pointer;
}

.tool.active {
  background: var(--ink);
  color: var(--white);
}

.size {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 999px;
  border: 1px solid rgba(26, 20, 16, 0.15);
  background: var(--white);
  position: relative;
  cursor: pointer;
}

.size::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: calc(var(--s, 8) * 1px);
  height: calc(var(--s, 8) * 1px);
  border-radius: 999px;
  background: var(--ink);
}

.size[data-size="3"] {
  --s: 4;
}
.size[data-size="8"] {
  --s: 8;
}
.size[data-size="16"] {
  --s: 14;
}
.size[data-size="28"] {
  --s: 20;
}

.size.active {
  background: rgba(212, 160, 23, 0.25);
}

.tool-hint {
  margin: 0;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.chat-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.35rem;
  flex: 0 0 auto;
}

.chat-log {
  flex: 1;
  overflow: auto;
  display: grid;
  gap: 0.4rem;
  padding: 0.35rem 0;
  font-size: 0.9rem;
  -webkit-overflow-scrolling: touch;
}

.chat-log .msg strong {
  display: block;
  font-size: 0.72rem;
  color: var(--ink-soft);
}

.chat-log .msg.system {
  color: var(--teal);
  font-weight: 600;
}

.chat-log .msg.correct {
  color: var(--teal);
}

#chat-form {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.35rem;
  flex: 0 0 auto;
}

#chat-form input {
  flex: 1;
  width: auto;
  min-width: 0;
  border-radius: 999px;
}

.podium li:nth-child(1) {
  background: rgba(212, 160, 23, 0.28);
}

dialog {
  border: 0;
  padding: 0;
  background: transparent;
  max-width: min(28rem, calc(100vw - 2rem));
  margin: auto;
}

dialog::backdrop {
  background: rgba(26, 20, 16, 0.5);
}

.dialog ol {
  padding-left: 1.2rem;
  color: var(--ink-soft);
  line-height: 1.5;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: max(1.25rem, calc(var(--safe-bottom) + 0.75rem));
  transform: translateX(-50%);
  max-width: calc(100vw - 2rem);
  background: var(--ink);
  color: var(--white);
  padding: 0.75rem 1.1rem;
  border-radius: 999px;
  font-weight: 500;
  z-index: 40;
  text-align: center;
}

@media (max-width: 959px) {
  .game-view {
    height: calc(100dvh - 3.1rem - var(--safe-top) - var(--safe-bottom)) !important;
    min-height: 0 !important;
    overflow: hidden;
  }

  body:has(.game-view.active) {
    overflow: hidden;
  }

  .game-shell {
    grid-template-columns: 1fr;
    /* Chat oben, Spieler, Canvas füllt Rest */
    grid-template-rows: auto auto minmax(0, 1fr);
    height: 100%;
    min-height: 0;
    gap: 0.45rem;
  }

  .chat-panel {
    order: -1;
    position: relative;
    height: auto;
    max-height: 18vh; /* Anteil der Bildschirmhöhe */
    min-height: 0;
    padding: 0.4rem 0.55rem;
    border-radius: 12px;
    transform: none;
    z-index: 1;
  }

  .chat-panel .chat-head {
    display: none;
  }

  .chat-panel .chat-log {
    /* ca. 2 Zeilen relativ zur Viewport-Höhe */
    max-height: 8vh;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    font-size: 0.78rem;
    line-height: 1.25;
    gap: 0.12rem;
    padding: 0;
    display: flex;
    flex-direction: column;
    justify-content: flex-end;
  }

  .chat-panel .chat-log .msg {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 0 0 auto;
  }

  .chat-panel .chat-log .msg strong {
    display: inline;
    margin-right: 0.3rem;
    font-size: inherit;
  }

  .chat-panel #chat-form {
    margin-top: 0.3rem;
    gap: 0.3rem;
  }

  .chat-panel #chat-form input {
    padding: 0.45rem 0.7rem;
    min-height: 2.4rem;
  }

  .chat-panel #chat-form .btn {
    padding: 0.45rem 0.7rem;
    min-height: 2.4rem;
  }

  .scoreboard-panel {
    order: 0;
    height: auto;
    max-height: none;
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 0.45rem;
    align-items: start;
    padding: 0.55rem;
  }

  .score-head {
    border-bottom: 0;
    margin-bottom: 0;
    padding-bottom: 0;
  }

  .scoreboard-panel .scores {
    grid-column: 1 / -1;
    display: flex;
    gap: 0.4rem;
    overflow-x: auto;
    max-height: none;
    flex: none;
    margin: 0.35rem 0 0;
    padding-bottom: 0.15rem;
  }

  .scores li {
    min-width: 9.5rem;
    flex: 0 0 auto;
  }

  #btn-abort {
    grid-column: 2;
    grid-row: 1;
    margin-top: 0;
  }

  .stage {
    order: 1;
    min-height: 0;
    height: 100%;
  }

  .canvas-wrap {
    min-height: 0;
    flex: 1 1 auto;
  }
}

@media (max-width: 560px) {
  .cta-row .btn {
    flex: 1 1 100%;
  }

  .field.inline {
    grid-template-columns: 1fr;
  }

  .field.inline input {
    width: 100%;
  }

  .tool {
    flex: 1 1 auto;
    text-align: center;
  }
}

@supports not (height: 100dvh) {
  html,
  body {
    min-height: 100vh;
  }

  .view {
    min-height: calc(100vh - 4rem);
  }
}
