* { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg:#1a1a1d; --panel:#26262b; --panel-2:#303036; --line:#3a3a42;
  --text:#f2f2f4; --muted:#9a9aa5; --accent:#e0322f; --accent-d:#b3201d;
}

body {
  font-family: "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--bg); color: var(--text);
  display: flex; justify-content: center; padding: 10px;
  -webkit-text-size-adjust: 100%;
}

.phone-frame {
  width: 393px; max-width: 100%; height: 852px; max-height: 96vh;
  background: var(--panel); border: 3px solid #000; border-radius: 4px;
  overflow: hidden; position: relative;
}

.screen { width: 100%; height: 100%; display: flex; flex-direction: column; }
.screen-title {
  background: #000; color: var(--text); padding: 14px; font-size: 18px;
  text-align: center; flex: 0 0 auto; border-bottom: 2px solid var(--accent);
}

.setup-body { flex: 1 1 auto; overflow-y: auto; padding: 0 16px; }
.setup-footer { flex: 0 0 auto; padding: 12px 16px 20px; }
.setup-row { display: flex; align-items: center; gap: 10px; margin-top: 18px; }
.setup-row label { width: 50px; font-size: 14px; }
.setup-row input {
  padding: 8px; border: 1px solid var(--line); border-radius: 5px; font-size: 15px;
  background: var(--panel-2); color: var(--text);
}
.setup-row #hanchanNo { width: 70px; }
.setup-row .unit { font-size: 14px; color: var(--muted); }
.setup-section-title {
  margin-top: 24px; font-size: 14px; font-weight: bold; color: var(--text);
  border-bottom: 2px solid var(--accent); padding-bottom: 4px;
}
.seat-setup { display: flex; flex-direction: column; gap: 10px; margin-top: 14px; }
.seat-pick { display: flex; align-items: center; gap: 10px; }
.seat-pick .wind {
  width: 36px; height: 36px; background: var(--accent); color: #fff;
  border-radius: 50%; display: flex; align-items: center; justify-content: center;
  font-weight: bold;
}
.seat-pick select {
  flex: 1; padding: 8px; border: 1px solid var(--line); border-radius: 5px;
  font-size: 15px; background: var(--panel-2); color: var(--text);
}

.primary-btn {
  width: 100%; background: var(--accent); color: #fff; border: none;
  border-radius: 8px; padding: 16px; font-size: 17px; font-weight: bold; cursor: pointer;
}
.primary-btn:active { background: var(--accent-d); }
.ghost-btn {
  width: 100%; margin-top: 10px; background: transparent; color: var(--text);
  border: 2px solid var(--line); border-radius: 8px; padding: 12px;
  font-size: 15px; font-weight: bold; cursor: pointer;
}
.ghost-btn.small { width: auto; margin: 0; padding: 8px 12px; font-size: 13px; }
.ghost-btn.danger { color: var(--accent); border-color: var(--accent); }

.input-area { flex: 1 1 60%; border-bottom: 3px solid #000; padding: 14px; overflow-y: auto; }
.score-area { flex: 1 1 40%; padding: 10px 14px; display: flex; flex-direction: column; }

.round-bar {
  display: flex; align-items: center; gap: 6px; background: #000;
  border-radius: 4px; padding: 8px 10px; margin-bottom: 14px; flex-wrap: wrap;
}
.round-bar select, .round-bar input {
  padding: 4px 6px; border: 1px solid var(--line); border-radius: 3px;
  font-size: 14px; background: var(--panel-2); color: var(--text);
}
.round-bar #honba { width: 46px; }
.round-bar .unit { color: var(--text); font-size: 13px; }
.mini-btn {
  background: var(--accent); color: #fff; font-weight: bold;
  padding: 4px 8px; border-radius: 4px; border: none; font-size: 13px; cursor: pointer;
}
#nextRoundBtn { margin-left: auto; }
.back-btn { background: var(--panel-2); color: var(--text); border: 1px solid var(--line); }
.back-btn:disabled { opacity: .4; cursor: not-allowed; }

.player-list { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.player-card {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 6px;
  padding: 8px 10px; display: flex; flex-direction: column; gap: 8px;
}
.player-card.has-agari { border-color: var(--accent); }

.pc-row1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pc-row1 .oya-mark {
  width: 24px; height: 24px; border-radius: 50%; background: #444;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: bold; color: var(--muted); flex: 0 0 auto;
}
.pc-row1 .oya-mark.is-oya { background: var(--accent); color: #fff; }
.pc-row1 .pc-name { font-weight: bold; font-size: 15px; flex: 0 0 auto; min-width: 52px; }

.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; }
.seg button {
  background: var(--panel); color: var(--muted); border: none;
  padding: 6px 10px; font-size: 13px; font-weight: bold; cursor: pointer;
  border-right: 1px solid var(--line);
}
.seg button:last-child { border-right: none; }
.seg button.active { background: var(--accent); color: #fff; }

.pc-row2 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.pc-input {
  padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px;
  font-size: 14px; background: var(--panel); color: var(--text);
}
.pc-input.junme { width: 64px; flex: 0 0 auto; }
.pc-input.agari { flex: 1; min-width: 90px; }
.pc-input.point { flex: 1; min-width: 80px; }
.pc-input:disabled { opacity: .35; }
.pc-label { font-size: 12px; color: var(--muted); }
.pc-sublabel { font-size: 11px; color: var(--muted); flex: 0 0 auto; }

.agari-detail { display: flex; flex-direction: column; gap: 8px; }
.agari-row { display: flex; align-items: center; gap: 8px; }
.btn-row { margin-top: 4px; }
.agari-row button {
  flex: 1; background: var(--accent); color: #fff; border: none;
  border-radius: 6px; padding: 12px; font-size: 15px; font-weight: bold; cursor: pointer;
}
.agari-row button:active { background: var(--accent-d); }
.sub-btns { gap: 8px; }
.sub-btn {
  background: var(--panel-2) !important; color: var(--text) !important;
  border: 1px solid var(--line) !important; font-size: 13px !important;
}
.sub-btn:active { background: var(--panel) !important; }
.end-btn { background: #555; }
.end-btn:active { background: #444; }

.score-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 6px; flex: 0 0 auto;
}
.kyotaku-label { font-size: 13px; color: var(--text); }
.kyotaku-label #kyotakuView { color: var(--accent); font-weight: bold; }
.rotate-btn {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 6px; padding: 6px 12px; font-size: 13px; font-weight: bold; cursor: pointer;
}
.rotate-btn:active { background: var(--panel); }

.table-wrap { flex: 1 1 auto; position: relative; }
.table-layout { position: absolute; inset: 0; min-height: 220px; }
.seat {
  position: absolute; background: var(--panel-2); color: var(--text);
  border: 1px solid var(--line); border-radius: 4px; padding: 8px 10px;
  text-align: center; font-size: 14px; min-width: 90px;
}
.seat .seat-name { font-size: 12px; color: var(--muted); }
.seat .seat-score { font-size: 18px; font-weight: bold; }
.seat-top    { top: 4%;  left: 50%; transform: translateX(-50%); }
.seat-bottom { bottom: 4%; left: 50%; transform: translateX(-50%); }
.seat-left   { left: 2%;  top: 50%; transform: translateY(-50%); }
.seat-right  { right: 2%; top: 50%; transform: translateY(-50%); }
.table-center {
  position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
  font-size: 12px; color: var(--muted); text-align: center; line-height: 1.4;
}

.result-meta { padding: 14px 16px; font-size: 13px; color: var(--muted); flex: 0 0 auto; }
.result-table {
  width: calc(100% - 24px); margin: 0 12px; border-collapse: collapse;
  font-size: 13px; flex: 0 0 auto;
}
.result-table th, .result-table td { border: 1px solid var(--line); padding: 8px 4px; text-align: center; }
.result-table th { background: #000; color: var(--text); }
.result-table .plus { color: #5cd65c; font-weight: bold; }
.result-table .minus { color: #ff6b6b; font-weight: bold; }
.result-table tr.rank1 td { background: #2e2a1a; }
.result-footer { margin-top: auto; padding: 16px; flex: 0 0 auto; }

.history-toolbar { display: flex; gap: 8px; padding: 12px 16px; flex: 0 0 auto; }
.history-list { flex: 1 1 auto; overflow-y: auto; padding: 0 12px; }
.history-empty { text-align: center; color: var(--muted); padding: 40px 0; }
.history-card {
  border: 1px solid var(--line); border-radius: 8px; margin-bottom: 12px; overflow: hidden;
}
.history-card .hc-head {
  background: #000; padding: 8px 12px; font-size: 13px; font-weight: bold; color: var(--text);
  display: flex; justify-content: space-between; align-items: center;
}
.history-card .hc-copy {
  background: var(--accent); color: #fff; border: none; border-radius: 4px;
  font-size: 11px; padding: 4px 8px; cursor: pointer;
}
.history-card table { width: 100%; border-collapse: collapse; font-size: 12px; }
.history-card td { border-top: 1px solid var(--line); padding: 6px 8px; }
.history-card td.r { text-align: right; }
.history-card td.plus { color: #5cd65c; }
.history-card td.minus { color: #ff6b6b; }

.hc-log {
  background: #1f1f23; padding: 8px 12px; font-size: 11px; color: var(--muted);
  white-space: pre-wrap; line-height: 1.5; border-top: 1px solid var(--line);
  font-family: "SFMono-Regular", Consolas, monospace;
}
.hc-log-toggle {
  background: var(--panel-2); color: var(--text); border: 1px solid var(--line);
  border-radius: 4px; font-size: 11px; padding: 4px 8px; cursor: pointer; margin-left: 6px;
}
