:root {
  --ink: #152033;
  --muted: #64748b;
  --panel: #ffffff;
  --line: #d7dee8;
  --green: #14745f;
  --green-dark: #0e5849;
  --coral: #d95d39;
  --gold: #f4bf45;
  --sky: #dff1ff;
  --text-font: "Apple SD Gothic Neo", "Malgun Gothic", "Noto Sans KR", Arial, Helvetica, sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(135deg, rgba(20, 116, 95, 0.16), transparent 32%),
    linear-gradient(315deg, rgba(217, 93, 57, 0.14), transparent 38%),
    #f5f8fb;
  font-family: var(--text-font);
}

.hidden {
  display: none !important;
}

.game {
  position: relative;
  display: grid;
  grid-template-rows: auto auto auto;
  gap: 12px;
  min-height: 0;
  padding: 14px 16px;
}

body.room-panel-collapsed .game {
  grid-template-rows: auto auto minmax(0, 1fr);
}

.topbar,
.panel-heading,
.header-actions,
.lobby-actions,
.lobby-button-row,
.lobby-player,
.size-control,
.player {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 12px;
}

.topbar > div:first-child {
  min-width: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 30px;
  line-height: 1;
}

h2 {
  font-size: 18px;
}

#contextLabel,
.panel-heading p {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

button {
  min-height: 36px;
  border: 0;
  border-radius: 8px;
  padding: 8px 12px;
  color: white;
  background: var(--green);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  cursor: pointer;
}

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

.header-actions {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.call-form {
  display: flex;
  align-items: center;
  gap: 6px;
}

.call-form input {
  width: min(34vw, 180px);
  min-height: 36px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 10px;
  color: var(--ink);
  background: var(--panel);
  font: inherit;
  font-size: 13px;
  font-weight: 800;
  line-height: 1.25;
}

#callButton {
  background: var(--coral);
}

#resetButton {
  background: #667085;
}

.danger-button {
  background: #b42318;
}

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

.status-section {
  display: grid;
}

.meter,
.lobby-panel,
.lobby-room-card,
.lobby-roster-card,
.card-panel,
.side-panel,
.result-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 14px 30px rgba(21, 32, 51, 0.08);
}

.lobby-panel {
  display: grid;
  grid-template-columns: minmax(180px, 0.7fr) minmax(220px, 0.9fr) minmax(260px, 1fr);
  gap: 14px;
  padding: 16px;
}

.lobby-room-card,
.lobby-settings-card,
.lobby-roster-card {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 14px;
  box-shadow: none;
}

.lobby-room-card {
  align-content: center;
  border-left: 6px solid var(--green);
  background: #f2fbf7;
}

.lobby-settings-card {
  align-content: start;
}

.size-control {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.size-control button {
  flex: 1 1 0;
  min-width: 70px;
  border-radius: 0;
  color: var(--green-dark);
  background: transparent;
}

.size-control button.selected {
  color: white;
  background: var(--green-dark);
}

.size-control.host-disabled button {
  opacity: 1;
}

.lobby-room-card span,
.lobby-actions p {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.lobby-room-card strong {
  color: var(--green-dark);
  font-size: clamp(42px, 10vw, 74px);
  line-height: 0.95;
  overflow-wrap: anywhere;
}

.lobby-roster-card {
  align-content: start;
}

.lobby-players {
  display: grid;
  gap: 7px;
}

.lobby-player {
  justify-content: space-between;
  gap: 10px;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--green);
  border-radius: 8px;
  background: #f8fafc;
}

.lobby-player strong {
  min-width: 0;
  overflow: hidden;
  font-size: 14px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-player span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.lobby-player.host {
  border-left-color: var(--gold);
  background: #fff8df;
}

.lobby-actions {
  grid-column: 1 / -1;
  justify-content: space-between;
  gap: 12px;
  min-width: 0;
}

.lobby-actions p {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lobby-actions button {
  flex: 1 1 0;
  min-width: 128px;
}

.lobby-button-row {
  flex: 0 1 auto;
  justify-content: flex-end;
  gap: 8px;
  min-width: min(100%, 272px);
}

#lobbyStartButton {
  background: var(--coral);
}

.meter {
  display: grid;
  gap: 4px;
  min-width: 0;
  padding: 10px 12px;
}

.meter span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.meter strong {
  overflow: hidden;
  font-size: 18px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

#cardMeta:empty {
  display: none;
}

.call-meter {
  border-left: 6px solid var(--coral);
  background: #fff8f5;
}

.call-meter strong {
  color: var(--coral);
  font-size: 28px;
  line-height: 1;
}

.table {
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(250px, 350px);
  gap: 14px;
  align-items: start;
}

.card-panel {
  grid-column: 1;
  grid-row: 1 / span 2;
}

.status-section,
.side-panel {
  grid-column: 2;
}

.card-panel,
.side-panel {
  display: grid;
  gap: 12px;
  padding: 14px;
}

.side-panel {
  align-content: start;
}

.side-panel section {
  display: grid;
  gap: 10px;
}

.panel-heading {
  justify-content: space-between;
  gap: 10px;
}

.panel-heading.compact {
  align-items: baseline;
}

.bingo-card {
  display: grid;
  gap: clamp(6px, 1.1vmin, 10px);
  width: min(86vmin, 620px);
  max-width: 100%;
  aspect-ratio: 1;
  margin: 0 auto;
  padding: clamp(8px, 1.5vmin, 14px);
  border: 3px solid var(--green-dark);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.22), transparent 30%),
    var(--green);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.bingo-card.size-3 {
  grid-template-columns: repeat(3, 1fr);
}

.bingo-card.size-5 {
  grid-template-columns: repeat(5, 1fr);
}

.cell {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 0;
  border: 2px solid rgba(14, 88, 73, 0.2);
  border-radius: 8px;
  color: var(--ink);
  background: #f8fbff;
  font-size: clamp(18px, 5vmin, 42px);
  font-weight: 900;
  line-height: 1.2;
  box-shadow: inset 0 -8px 14px rgba(21, 32, 51, 0.05);
}

.cell {
  padding: clamp(5px, 1vmin, 9px);
}

.size-5 .cell {
  font-size: clamp(15px, 3.7vmin, 32px);
}

.cell input {
  width: 100%;
  min-width: 0;
  height: 100%;
  min-height: 0;
  border: 0;
  color: inherit;
  background: transparent;
  font-family: var(--text-font);
  font-size: clamp(13px, 2.8vmin, 24px);
  font-weight: 800;
  line-height: 1.22;
  text-align: center;
  padding: 0 18px 0 4px;
  overflow: hidden;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

.size-5 .cell input {
  font-size: clamp(12px, 1.9vmin, 18px);
  line-height: 1.28;
  padding-right: 14px;
}

.cell input:focus {
  outline: 0;
}

.cell:focus-within {
  outline: 3px solid var(--coral);
  outline-offset: -5px;
}

.mark-button {
  position: absolute;
  right: 5px;
  bottom: 5px;
  display: grid;
  place-items: center;
  width: 24px;
  height: 24px;
  min-height: 0;
  padding: 0;
  color: var(--green-dark);
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(14, 88, 73, 0.18);
  border-radius: 50%;
  font-size: 13px;
  font-weight: 900;
  line-height: 1;
}

.size-5 .mark-button {
  right: 3px;
  bottom: 3px;
  width: 18px;
  height: 18px;
  font-size: 10px;
}

.cell.marked .mark-button {
  color: white;
  background: var(--green-dark);
}

.cell.marked {
  color: var(--green-dark);
  background:
    radial-gradient(circle at 50% 50%, rgba(244, 191, 69, 0.32), transparent 58%),
    var(--sky);
  border-color: var(--gold);
}

.cell.latest {
  outline: 4px solid var(--coral);
  outline-offset: -6px;
}

.empty-card {
  grid-column: 1 / -1;
  align-self: center;
  justify-self: center;
  color: rgba(255, 255, 255, 0.86);
  font-size: 18px;
  font-weight: 900;
}

.called-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.called-number {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 24px;
  max-width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--line);
  border-radius: 6px;
  color: var(--muted);
  background: #f8fafc;
  font-family: var(--text-font);
  font-size: 11px;
  font-weight: 800;
  line-height: 1.3;
  overflow-wrap: anywhere;
  word-break: keep-all;
}

.called-empty {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.called-number.called {
  color: white;
  border-color: var(--green);
  background: var(--green);
}

.called-number.latest {
  color: white;
  border-color: var(--coral);
  background: var(--coral);
}

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

.player {
  justify-content: space-between;
  gap: 8px;
  min-height: 34px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-left: 4px solid transparent;
  border-radius: 8px;
  background: #f8fafc;
}

.player strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.player span {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.player.winner {
  border-left-color: var(--gold);
  background: #fff8df;
}

.player.caller {
  border-left-color: var(--coral);
  background: #fff8f5;
}

.player.caller span {
  color: var(--coral);
}

.result-overlay {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(21, 32, 51, 0.48);
}

.result-box {
  display: grid;
  gap: 16px;
  width: min(92vw, 520px);
  padding: 26px;
  border: 2px solid var(--gold);
  text-align: center;
}

#resultMessage {
  color: var(--green-dark);
  font-size: clamp(36px, 9vmin, 72px);
  font-weight: 900;
  line-height: 1.05;
}

.result-box button {
  justify-self: center;
  min-width: 110px;
}

@media (max-width: 860px) {
  .lobby-panel {
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  }

  .lobby-actions {
    grid-column: 1 / -1;
  }

  .lobby-roster-card {
    grid-column: auto;
  }

  .status-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

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

  .card-panel,
  .status-section,
  .side-panel {
    grid-column: auto;
    grid-row: auto;
  }

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

@media (max-width: 620px) {
  .game {
    padding: 10px 12px;
  }

  .topbar {
    align-items: flex-start;
  }

  h1 {
    font-size: 26px;
  }

  .header-actions {
    gap: 6px;
  }

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

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

  .lobby-actions,
  .lobby-roster-card {
    grid-column: auto;
  }

  .lobby-actions p {
    white-space: normal;
  }

  .lobby-button-row {
    width: 100%;
  }

  .lobby-actions button {
    min-width: 0;
  }

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