:root {
  color-scheme: dark;
  --bg: #111318;
  --panel: #1d222b;
  --panel-2: #252b35;
  --text: #f7f3eb;
  --muted: #aeb6c3;
  --line: #3a4150;
  --gold: #f4c35d;
  --red: #e45b55;
  --green: #49c08e;
}

* {
  box-sizing: border-box;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

button,
input {
  font: inherit;
}

.app {
  min-height: 100dvh;
  height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) 12px max(12px, env(safe-area-inset-bottom));
}

.hidden {
  display: none !important;
}

.join-view {
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
  max-width: 560px;
  margin: 0 auto;
  min-height: 0;
}

.join-header {
  display: grid;
  gap: 10px;
}

.brand {
  text-align: center;
  font-size: 26px;
  font-weight: 800;
  letter-spacing: 0;
}

.join-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 72px 72px;
  gap: 8px;
  width: 100%;
}

.join-card input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  height: 46px;
  padding: 0 12px;
  outline: none;
  font-size: 16px;
}

.join-card button,
.action {
  border: 0;
  border-radius: 8px;
  color: #111318;
  font-weight: 800;
}

.join-card button {
  height: 46px;
  background: var(--gold);
}

.join-card .create-room {
  background: var(--green);
}

.room-list-section {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
}

.list-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--muted);
  font-size: 13px;
}

.list-head strong {
  color: var(--text);
  font-size: 16px;
}

.room-list {
  min-height: 0;
  overflow: auto;
  display: grid;
  align-content: start;
  gap: 8px;
  padding-bottom: 2px;
}

.room-item {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--text);
  min-height: 58px;
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.room-item:disabled {
  opacity: 0.5;
}

.room-number {
  font-size: 22px;
  font-weight: 850;
  color: var(--gold);
}

.room-meta {
  flex: 0 0 auto;
  color: var(--muted);
  font-size: 13px;
}

.empty-list {
  border: 1px dashed var(--line);
  border-radius: 8px;
  min-height: 96px;
  display: grid;
  place-items: center;
  color: var(--muted);
  text-align: center;
}

.game-view {
  height: 100%;
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 8px;
  max-width: 560px;
  margin: 0 auto;
}

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

.top-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.label {
  color: var(--muted);
  font-size: 12px;
}

.room {
  font-size: 22px;
  font-weight: 800;
  line-height: 1.1;
}

.round-pill {
  flex: 0 0 auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--gold);
  padding: 7px 12px;
  font-weight: 700;
}

.leave-btn {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--muted);
  height: 34px;
  min-width: 56px;
  padding: 0 10px;
  font-weight: 700;
}

.status {
  min-height: 28px;
  display: grid;
  place-items: center;
  border-radius: 8px;
  background: #181c24;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  padding: 4px 8px;
}

.board {
  min-height: 0;
  display: grid;
  grid-template-rows: 1fr 1fr;
  gap: 8px;
}

.player-panel {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 8px;
  border-radius: 8px;
  background: var(--panel);
  border: 1px solid var(--line);
  padding: 10px;
}

.mine {
  border-color: rgba(244, 195, 93, 0.65);
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  color: var(--muted);
  font-size: 13px;
}

.panel-head strong {
  color: var(--text);
  font-size: 16px;
}

.dice-row {
  min-height: 0;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: center;
  gap: 7px;
}

.die {
  aspect-ratio: 1;
  min-width: 0;
  border-radius: 8px;
  background: #f8f0df;
  border: 2px solid #d8c6a7;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  padding: 12%;
  box-shadow: inset 0 -6px 0 rgba(0, 0, 0, 0.08);
}

.die.hidden-die {
  background: var(--panel-2);
  border-color: #434a57;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: clamp(18px, 8vw, 34px);
  font-weight: 900;
}

.dot {
  width: 62%;
  height: 62%;
  align-self: center;
  justify-self: center;
  border-radius: 50%;
  background: #20242b;
}

.p1 { grid-area: 1 / 1; }
.p2 { grid-area: 1 / 2; }
.p3 { grid-area: 1 / 3; }
.p4 { grid-area: 2 / 1; }
.p5 { grid-area: 2 / 2; }
.p6 { grid-area: 2 / 3; }
.p7 { grid-area: 3 / 1; }
.p8 { grid-area: 3 / 2; }
.p9 { grid-area: 3 / 3; }

.actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.action {
  height: 54px;
  font-size: 20px;
}

.open {
  background: var(--red);
  color: #fff;
}

.next {
  background: var(--green);
}

.action.selected {
  outline: 3px solid var(--gold);
  outline-offset: -3px;
}

.action:disabled {
  opacity: 0.45;
}

@media (max-height: 640px) {
  .app {
    padding-top: 8px;
    padding-bottom: 8px;
  }

  .game-view,
  .board,
  .player-panel {
    gap: 6px;
  }

  .player-panel {
    padding: 8px;
  }

  .room {
    font-size: 19px;
  }

  .status {
    min-height: 24px;
    font-size: 12px;
  }

  .action {
    height: 48px;
    font-size: 18px;
  }
}
