:root {
  --bg: #0f1c14;
  --felt: #1a3a28;
  --felt-2: #143222;
  --gold: #e4c36a;
  --gold-dim: #b8943e;
  --ink: #f4efe4;
  --muted: #b7c4b8;
  --danger: #e26d6d;
  --ok: #7dce9a;
  --panel: #12261b;
  --line: rgba(228, 195, 106, 0.28);
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.35);
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  background: radial-gradient(circle at top, #234a33, var(--bg) 58%);
  color: var(--ink);
}

body {
  max-width: 520px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}

button,
input,
select {
  font: inherit;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 5;
  padding: calc(14px + env(safe-area-inset-top)) 16px 10px;
  background: linear-gradient(180deg, #0f1c14 70%, transparent);
  text-align: center;
}

.app-header h1 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: 0.04em;
  color: var(--gold);
  font-weight: 700;
}

.screen {
  display: none;
  padding: 0 14px 28px;
}

.screen.active {
  display: block;
}

.screen.with-tabs {
  padding-bottom: 96px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 14px;
  margin-bottom: 12px;
  box-shadow: var(--shadow);
}

.card h2 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  color: var(--gold);
}

.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 8px 0;
}

label.field {
  display: block;
  width: 100%;
  font-size: 0.85rem;
  color: var(--muted);
}

input[type="text"],
input[type="number"] {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0d1a13;
  color: var(--ink);
}

.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--ink);
}

.btn {
  appearance: none;
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  background: var(--gold);
  color: #1a1406;
  font-weight: 700;
  width: 100%;
}

.btn.ghost {
  background: transparent;
  color: var(--gold);
  border: 1px solid var(--line);
}

.btn.danger {
  background: var(--danger);
  color: #2a0c0c;
}

.btn.ok {
  background: var(--ok);
  color: #0d2416;
}

.btn:disabled {
  opacity: 0.45;
}

.table-hint {
  text-align: center;
  margin: -6px 0 8px;
}

#btn-set-dealer {
  margin-top: 4px;
}

.btn-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.btn-row.triple {
  grid-template-columns: 1fr 1fr 1fr;
}

.btn-row.triple .btn {
  padding: 10px 6px;
  font-size: 0.88rem;
}

.hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.player-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.player-edit {
  display: grid;
  grid-template-columns: 52px 1fr;
  gap: 8px;
  align-items: center;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 12px;
}

.avatar {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: #0d1a13;
  border: 2px solid var(--gold-dim);
  display: grid;
  place-items: center;
  overflow: hidden;
  font-size: 1.4rem;
}

.avatar img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.animal-select,
select {
  width: 100%;
  margin-top: 4px;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #0d1a13;
  color: var(--ink);
}

.player-edit .animal-select {
  margin-top: 0;
  padding: 8px;
  font-size: 0.9rem;
}

.table-wrap {
  display: grid;
  grid-template-columns: minmax(96px, 1fr) minmax(110px, 1.15fr) minmax(96px, 1fr);
  grid-template-rows: auto minmax(92px, 1fr) auto;
  align-items: center;
  justify-items: center;
  gap: 8px 6px;
  min-height: 420px;
  aspect-ratio: 1 / 1.12;
  max-height: 520px;
  margin: 8px 0 14px;
  padding: 10px 8px;
  background: radial-gradient(circle, var(--felt) 0%, var(--felt-2) 70%);
  border: 6px solid #6b5424;
  border-radius: 24px;
  box-shadow: inset 0 0 40px rgba(0, 0, 0, 0.35), var(--shadow);
}

.seat {
  position: relative;
  width: 100%;
  max-width: 128px;
  background: rgba(10, 22, 16, 0.88);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 8px 6px;
  text-align: center;
  color: inherit;
  appearance: none;
}

.seat.north {
  grid-column: 2;
  grid-row: 1;
}
.seat.south {
  grid-column: 2;
  grid-row: 3;
}
.seat.west {
  grid-column: 1;
  grid-row: 2;
}
.seat.east {
  grid-column: 3;
  grid-row: 2;
}

.seat.dealer {
  border-color: var(--gold);
  box-shadow: 0 0 0 1px var(--gold);
}

.seat .avatar {
  width: 40px;
  height: 40px;
  font-size: 1.2rem;
}

.seat-head {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  flex-wrap: wrap;
}

.label {
  display: inline-block;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  padding: 2px 5px;
  border-radius: 4px;
  background: var(--gold);
  color: #1a1406;
  line-height: 1.2;
}

.seat .name {
  font-weight: 700;
  font-size: 0.78rem;
  margin-top: 4px;
  line-height: 1.25;
}

.seat .score {
  font-size: 1.05rem;
  color: var(--gold);
}

.seat .meta {
  font-size: 0.68rem;
  color: var(--muted);
  min-height: 0.8em;
}

.table-center {
  grid-column: 2;
  grid-row: 2;
  position: relative;
  text-align: center;
  z-index: 2;
}

.round-label {
  font-size: 0.92rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--gold);
  margin-bottom: 6px;
}

.btn-draw {
  width: auto;
  min-width: 72px;
  padding: 7px 12px;
  font-size: 0.82rem;
}

.log {
  max-height: none;
  overflow: visible;
  font-size: 0.88rem;
  color: var(--muted);
}

.log div {
  padding: 6px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
}

.la-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 10px 0 14px;
}

.la-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #0d1a13;
}

.la-row.alert {
  border-color: var(--gold);
}

.la-row.pending {
  opacity: 0.72;
}

.la-row .la-main {
  font-size: 0.88rem;
  line-height: 1.4;
}

.la-row .avatar {
  width: 32px;
  height: 32px;
  display: inline-grid;
  vertical-align: middle;
  font-size: 1rem;
}

.la-row .btn {
  width: auto;
  padding: 8px 12px;
  font-size: 0.82rem;
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.62);
  z-index: 20;
  padding: 18px 12px;
  overflow: auto;
}

.modal.active {
  display: block;
}

.modal .sheet {
  max-width: 520px;
  margin: 24px auto;
}

.choice-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.choice {
  border: 1px solid var(--line);
  background: #0d1a13;
  color: var(--ink);
  border-radius: 12px;
  padding: 10px;
  text-align: left;
}

.choice.selected {
  border-color: var(--gold);
  color: var(--gold);
}

.preview {
  font-size: 0.88rem;
  line-height: 1.45;
  background: #0d1a13;
  border-radius: 12px;
  padding: 10px;
  margin-top: 8px;
}

.hidden-file {
  display: none;
}

.tab-bar {
  display: none;
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%);
  width: 100%;
  max-width: 520px;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 0;
  z-index: 12;
  background: rgba(15, 28, 20, 0.96);
  border-top: 1px solid var(--line);
  padding: 6px 8px calc(8px + env(safe-area-inset-bottom));
}

.tab-bar.visible {
  display: grid;
}

.tab-item {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 700;
  font-size: 0.78rem;
  padding: 8px 6px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.tab-item.active {
  color: var(--gold);
}

.tab-icon {
  font-size: 1.2rem;
  line-height: 1.2;
}

.log-score-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.06);
  font-size: 0.92rem;
}

.log-score-row .score {
  color: var(--gold);
  font-weight: 700;
}

.stat-card {
  background: #f4eee4;
  color: #2c2518;
  border-radius: 18px;
  padding: 14px 14px 10px;
  margin-bottom: 10px;
  box-shadow: var(--shadow);
}

.stat-head {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.stat-head .avatar {
  width: 44px;
  height: 44px;
  flex: none;
  background: #e8dfd0;
}

.stat-name {
  font-weight: 800;
  font-size: 0.98rem;
  line-height: 1.3;
  flex: 1;
  min-width: 0;
}

.stat-titles {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 4px;
  max-width: 58%;
}

.stat-pill {
  background: #e7ddce;
  color: #6d5f4a;
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.68rem;
  font-weight: 700;
  white-space: nowrap;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 4px;
  margin-top: 12px;
  text-align: center;
}

.stat-cell .num {
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.03em;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.stat-cell .lbl {
  font-size: 0.7rem;
  color: #8a7c68;
  margin-top: 2px;
}

.stat-crown {
  color: #c9a227;
  font-size: 0.85rem;
  line-height: 1;
}

.screen-log {
  padding-left: 8px;
  padding-right: 8px;
}

.log-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.log-seg {
  display: flex;
  background: #f4eee4;
  border-radius: 999px;
  padding: 3px;
}

.log-seg-btn {
  appearance: none;
  border: 0;
  background: transparent;
  color: #7a6d5b;
  font-weight: 700;
  font-size: 0.75rem;
  padding: 6px 10px;
  border-radius: 999px;
}

.log-seg-btn.on {
  background: #fff;
  color: #2c2518;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.08);
}

.log-grid {
  display: grid;
  grid-template-columns: 34px 1fr 1fr 1fr 1fr;
  gap: 4px;
  align-items: start;
}

.log-head {
  position: sticky;
  top: calc(46px + env(safe-area-inset-top));
  z-index: 4;
  padding-bottom: 8px;
  background: linear-gradient(180deg, #0f1c14 55%, transparent);
}

.log-col-head {
  background: #f4eee4;
  color: #2c2518;
  border-radius: 14px 14px 0 0;
  padding: 10px 4px 8px;
  text-align: center;
}

.log-col-head .avatar {
  width: 36px;
  height: 36px;
  margin: 0 auto 4px;
  background: #e8dfd0;
}

.log-head-name {
  font-size: 0.72rem;
  font-weight: 800;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.log-head-score {
  font-size: 0.95rem;
  font-weight: 800;
  margin-top: 2px;
}

.log-stream {
  background: #f4eee4;
  border-radius: 0 0 16px 16px;
  margin-top: -2px;
  padding-bottom: 12px;
}

.log-row {
  display: grid;
  grid-template-columns: 34px 1fr 1fr 1fr 1fr;
  gap: 4px;
  width: 100%;
  appearance: none;
  border: 0;
  background: transparent;
  padding: 8px 0 10px;
  border-top: 1px solid rgba(80, 60, 30, 0.08);
  text-align: center;
  color: inherit;
}

.log-row.open {
  background: rgba(255, 255, 255, 0.45);
}

.log-rail {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  color: #8a7c68;
  min-height: 42px;
  position: relative;
}

.log-rail-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #c9b48a;
  margin-top: 6px;
}

.log-rail-line {
  width: 2px;
  flex: 1;
  min-height: 28px;
  background: #e0d4c2;
  margin-top: 4px;
}

.log-rail-wind {
  font-size: 0.72rem;
  font-weight: 800;
  color: #6d5f4a;
  margin-top: 4px;
}

.log-rail-meta {
  font-size: 0.58rem;
  writing-mode: horizontal-tb;
}

.log-cell {
  padding: 0 2px;
  min-height: 44px;
}

.log-delta {
  font-size: 0.95rem;
  font-weight: 800;
}

.log-head-score.pos,
.log-delta.pos {
  color: #1f9a66;
}

.log-head-score.neg,
.log-delta.neg {
  color: #d24b45;
}

.log-head-score.zero,
.log-delta.zero {
  color: #9a8d7a;
}

.log-tags {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  margin-top: 4px;
}

.log-tag {
  display: inline-block;
  background: #e7ddce;
  color: #6d5f4a;
  border-radius: 999px;
  padding: 2px 7px;
  font-size: 0.62rem;
  font-weight: 700;
}

.log-tag.tag-dealer {
  background: #efe6d4;
}

.log-tag.tag-good {
  color: #1f9a66;
  background: #dcefe4;
}

.log-tag.tag-bad {
  color: #b5524c;
  background: #f3e0dc;
}

.log-detail {
  padding: 0 12px 10px 46px;
  color: #6d5f4a;
  font-size: 0.75rem;
}

.log-detail-text {
  background: #efe7d8;
  border-radius: 10px;
  padding: 8px 10px;
  line-height: 1.4;
}
