/* Rich4 room server pages: login, rooms, lobby, game, admin. */
:root {
  --bg: #12151c;
  --bg-raised: #1a1f29;
  --bg-sunken: #0d1015;
  --line: #2b3240;
  --text: #e8ecf2;
  --text-dim: #9aa4b5;
  --accent: #f59e0b;
  --accent-strong: #fbbf24;
  --accent-text: #1a1204;
  --ok: #34d399;
  --warn: #fbbf24;
  --error: #f87171;
  --info: #60a5fa;
  --seat-0: #ef4444;
  --seat-1: #3b82f6;
  --seat-2: #22c55e;
  --seat-3: #eab308;
  --radius: 10px;
  --shadow: 0 10px 30px rgb(0 0 0 / 0.35);
  --font: 'Noto Sans TC', 'Microsoft JhengHei', 'PingFang TC', system-ui, sans-serif;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f4ef;
    --bg-raised: #ffffff;
    --bg-sunken: #ece8df;
    --line: #ddd6c8;
    --text: #1f2430;
    --text-dim: #5d6575;
    --accent: #d97706;
    --accent-strong: #b45309;
    --accent-text: #ffffff;
    --ok: #047857;
    --warn: #b45309;
    --error: #b91c1c;
    --info: #1d4ed8;
    --shadow: 0 10px 30px rgb(60 50 30 / 0.12);
    color-scheme: light;
  }
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  line-height: 1.6;
}

a {
  color: var(--accent);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---- layout ---- */
.page {
  min-height: 100vh;
}

.wrap {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 20px;
}

.topbar h1 {
  margin: 0;
  font-size: 1.4rem;
  flex: 1;
  min-width: 0;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 7px;
  background: var(--accent);
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  padding: 5px;
  gap: 2px;
}

.brand-mark i {
  width: 4px;
  height: 4px;
  border-radius: 50%;
  background: var(--accent-text);
  align-self: center;
  justify-self: center;
}

.panel {
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
}

.panel h2 {
  margin: 0 0 12px;
  font-size: 1.05rem;
}

.muted {
  color: var(--text-dim);
}

.row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
}

/* ---- controls ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  color: var(--text);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.btn:hover {
  border-color: var(--accent);
}

.btn:focus-visible,
.input:focus-visible,
select:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

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

.btn svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.btn-primary,
.btn-gold {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
}

.btn-primary:hover,
.btn-gold:hover {
  background: var(--accent-strong);
}

.btn-ghost {
  background: transparent;
}

.btn-danger {
  color: var(--error);
}

.btn-sm {
  min-height: 32px;
  padding: 4px 10px;
  font-size: 0.9rem;
}

.btn-block {
  width: 100%;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.field label {
  font-size: 0.9rem;
  color: var(--text-dim);
}

.input,
select {
  min-height: 40px;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  color: var(--text);
  font: inherit;
}

.notice {
  padding: 10px 12px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  margin: 0 0 12px;
}

.notice[data-kind='ok'] {
  border-color: var(--ok);
}

.notice[data-kind='error'] {
  border-color: var(--error);
  color: var(--error);
}

.notice[data-kind='info'] {
  border-color: var(--info);
}

.badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  border: 1px solid var(--line);
  white-space: nowrap;
}

.badge[data-kind='ok'],
.badge[data-kind='lobby'] {
  border-color: var(--ok);
  color: var(--ok);
}

.badge[data-kind='playing'],
.badge[data-kind='admin'] {
  border-color: var(--accent);
  color: var(--accent);
}

.badge[data-kind='paused'],
.badge[data-kind='pending'] {
  border-color: var(--warn);
  color: var(--warn);
}

.badge[data-kind='off'] {
  border-color: var(--error);
  color: var(--error);
}

/* ---- login (from the San7 version) ---- */
.auth {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 16px;
}

.auth-card {
  width: min(420px, 100%);
  background: var(--bg-raised);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 28px 24px;
  box-shadow: var(--shadow);
}

.auth-title {
  margin: 0 0 6px;
  font-size: 1.6rem;
  text-align: center;
}

.auth-lead {
  margin: 0 0 20px;
  text-align: center;
  color: var(--text-dim);
}

.auth-foot {
  margin: 18px 0 0;
  text-align: center;
  color: var(--text-dim);
  font-size: 0.9rem;
}

.divider {
  text-align: center;
  color: var(--text-dim);
  margin: 12px 0;
}

/* ---- admin ---- */
.admin {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 48px;
}

.admin-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}

.invite-form {
  display: grid;
  grid-template-columns: 1fr 1fr auto;
  gap: 12px;
  align-items: end;
}

.invite-form .field {
  margin: 0;
}

.table-wrap {
  overflow-x: auto;
}

.table {
  width: 100%;
  border-collapse: collapse;
}

.table th,
.table td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}

.table .num {
  text-align: right;
}

.row-actions {
  display: flex;
  gap: 6px;
  justify-content: flex-end;
}

/* ---- rooms ---- */
.room-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 10px;
}

.room-item a,
.room-item .room-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-raised);
  color: var(--text);
  text-decoration: none;
}

.room-item a:hover {
  border-color: var(--accent);
}

.room-item .name {
  flex: 1;
  min-width: 0;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ---- lobby ---- */
.seats {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}

.seat {
  border: 1px solid var(--line);
  border-left: 5px solid var(--seat-color, var(--line));
  border-radius: var(--radius);
  padding: 12px;
  background: var(--bg-sunken);
  min-height: 110px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.seat[data-seat='0'] {
  --seat-color: var(--seat-0);
}

.seat[data-seat='1'] {
  --seat-color: var(--seat-1);
}

.seat[data-seat='2'] {
  --seat-color: var(--seat-2);
}

.seat[data-seat='3'] {
  --seat-color: var(--seat-3);
}

.seat .who {
  font-weight: 700;
}

.seat .what {
  color: var(--text-dim);
  font-size: 0.92rem;
}

.seat .btn {
  margin-top: auto;
}

.chars {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 8px;
}

.char {
  min-height: 44px;
  border-radius: 8px;
  border: 1px solid var(--line);
  background: var(--bg-sunken);
  color: var(--text);
  font: inherit;
  cursor: pointer;
}

.char[aria-pressed='true'] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.char:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.settings {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 12px;
}

.settings .field {
  margin: 0;
}

.member-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.member-list li {
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  font-size: 0.9rem;
}

.link-box {
  display: flex;
  gap: 8px;
}

.link-box .input {
  flex: 1;
  min-width: 0;
}

/* ---- game ---- */
.play {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  gap: 16px;
  max-width: 1320px;
  margin: 0 auto;
  padding: 12px 16px 24px;
}

.screen-wrap {
  position: relative;
  background: #000;
  border-radius: var(--radius);
  overflow: hidden;
  aspect-ratio: 4 / 3;
  width: 100%;
  max-height: calc(100vh - 90px);
  margin: 0 auto;
}

#screen {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
  image-rendering: pixelated;
  cursor: default;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}

.touch-hint {
  display: none;
  font-size: 0.85rem;
  margin: 0;
}

@media (pointer: coarse) {
  .touch-hint {
    display: block;
  }
}

.screen-wrap[data-turn='mine'] {
  box-shadow: 0 0 0 3px var(--accent);
}

.overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgb(0 0 0 / 0.55);
  color: #fff;
  text-align: center;
  padding: 16px;
}

.overlay[hidden] {
  display: none;
}

.side {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.turn {
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  background: var(--bg-raised);
  font-weight: 700;
}

.turn[data-mine='true'] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

.players {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.players li {
  padding: 8px 10px;
  border-radius: 8px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--seat-color, var(--line));
  background: var(--bg-raised);
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 2px 8px;
  font-size: 0.92rem;
}

.players li[data-seat='0'] {
  --seat-color: var(--seat-0);
}

.players li[data-seat='1'] {
  --seat-color: var(--seat-1);
}

.players li[data-seat='2'] {
  --seat-color: var(--seat-2);
}

.players li[data-seat='3'] {
  --seat-color: var(--seat-3);
}

.players li[data-active='true'] {
  outline: 2px solid var(--accent);
}

.players .tag {
  color: var(--text-dim);
  font-size: 0.8rem;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  margin-right: 6px;
}

.dot[data-on='true'] {
  background: var(--ok);
}

.volume {
  width: 100%;
}

@media (max-width: 900px) {
  .play {
    grid-template-columns: 1fr;
  }

  .invite-form {
    grid-template-columns: 1fr;
  }
}

/* ---- phones ---- */
@media (max-width: 600px) {
  .wrap {
    padding: 16px 12px 32px;
  }

  .play {
    padding: 0 0 16px;
    gap: 10px;
  }

  /* the picture goes edge to edge */
  .screen-wrap {
    border-radius: 0;
  }

  .side {
    padding: 0 12px;
    gap: 10px;
  }

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

/* phones held sideways: the picture takes the full height, the panel scrolls beside it */
@media (orientation: landscape) and (max-height: 500px) {
  .play {
    grid-template-columns: minmax(0, 1fr) 210px;
    max-width: none;
    padding: 0;
    gap: 8px;
  }

  .screen-wrap {
    border-radius: 0;
    max-height: 100vh;
    max-height: 100dvh;
  }

  .side {
    max-height: 100vh;
    max-height: 100dvh;
    overflow-y: auto;
    padding: 8px 8px 8px 0;
    gap: 8px;
    font-size: 0.9rem;
  }
}
