:root {
  --bg: #1b1f2e;
  --card: #262b3b;
  --text: #eef0f3;
  --muted: #9aa3ae;
  --accent: #ffd84a;
  --danger: #ff6b6b;
  --pixel: "Press Start 2P", monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html,
body {
  height: 100%;
}

body {
  background: var(--bg);
  font-family: system-ui, sans-serif;
  color: var(--text);
  overflow: hidden;
  touch-action: manipulation;
}

/* ---------- Screens ---------- */
.screen {
  display: none;
  height: 100%;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 16px;
}

.screen.active {
  display: flex;
}

.hidden {
  display: none !important;
}

h1 {
  font-family: var(--pixel);
  font-size: clamp(20px, 5vw, 36px);
  color: var(--accent);
  text-shadow: 3px 3px 0 #000;
  text-align: center;
}

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

label {
  font-size: 0.9rem;
  color: var(--muted);
}

input {
  width: 100%;
  padding: 10px 12px;
  font-size: 1rem;
  border-radius: 8px;
  border: 1px solid #3a404b;
  background: #15181d;
  color: var(--text);
}

#code {
  text-transform: uppercase;
  letter-spacing: 0.2em;
}

button {
  font-family: inherit;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 600;
  border-radius: 8px;
  border: none;
  cursor: pointer;
  background: #3a404b;
  color: var(--text);
  white-space: nowrap;
}

button:hover:not(:disabled) {
  filter: brightness(1.15);
}

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

button.primary {
  background: var(--accent);
  color: #1a1a1a;
}

.row {
  display: flex;
  gap: 8px;
}

.divider {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.8rem;
}

.divider::before,
.divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: #3a404b;
}

/* Invite link: joining that one lobby is the only sensible action. */
#screen-home.invited #create,
#screen-home.invited #or-divider,
#screen-home.invited #code {
  display: none;
}

#screen-home.invited #join {
  flex: 1;
}

.hint .code,
#lobby-code {
  font-family: var(--pixel);
  color: var(--accent);
  letter-spacing: 0.1em;
  white-space: nowrap;
}

.error {
  color: var(--danger);
  min-height: 1.2em;
}

.hint {
  color: var(--muted);
  text-align: center;
}

#player-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 4px 0;
}

#player-list li {
  background: #15181d;
  padding: 10px 12px;
  border-radius: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

#player-list li.empty {
  color: var(--muted);
  font-style: italic;
}

.tag {
  font-size: 0.75rem;
  color: var(--accent);
}

/* ---------- Table ---------- */
#screen-game {
  padding: 0;
}

#stage {
  position: relative;
  width: min(96vw, calc(96dvh * 4 / 3));
  aspect-ratio: 4 / 3;
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.5);
  user-select: none;
  -webkit-user-select: none;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

#actions {
  position: absolute;
  right: 3%;
  bottom: 17%;
  display: flex;
  gap: 10px;
}

#actions button,
.panel button {
  font-size: clamp(12px, 2vmin, 18px);
  font-weight: 700;
  padding: 0.6em 1.4em;
  color: #fff;
  background: #e8722b;
  border: 3px solid #000;
  box-shadow: 0 4px 0 #000;
}

#actions button:active,
.panel button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #000;
}

#actions button.secondary {
  background: #3a8fd8;
}

.panel button:disabled {
  background: #555;
}

.panel {
  position: absolute;
  left: 50%;
  top: 44%;
  transform: translate(-50%, -50%);
  min-width: 40%;
  max-width: 70%;
  padding: 2.5vmin 3vmin;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.2vmin;
  text-align: center;
  background: rgba(10, 20, 30, 0.88);
  border: 2px solid var(--accent);
  border-radius: 12px;
  font-size: clamp(11px, 1.8vmin, 16px);
}

.panel h2 {
  font-size: clamp(18px, 4vmin, 34px);
  color: var(--accent);
}

#yaku {
  list-style: none;
  line-height: 1.6;
}

#points {
  font-weight: 700;
  font-size: 1.2em;
}

#deltas td {
  padding: 0 0.8em;
}

.plus {
  color: #7fe39a;
}

.minus {
  color: #ff9a8a;
}
