:root {
  /* 對齊 tkd_erp_saas 淺底＋鼴尾草綠 */
  --bg: #f5f3ef;
  --panel: #fffcf9;
  --panel-2: #eceae6;
  --line: #e2ded8;
  --text: #2d3432;
  --muted: #5c6563;
  --blue: #1d5cff;
  --blue-deep: #0d2d86;
  --red: #e31b23;
  --red-deep: #7a0d12;
  --brand: #5f7f79;
  --brand-hover: #4d6964;
  --brand-subtle: #e8efed;
  --gold: var(--brand);
  --ok: #6b9080;
  --shadow: 0 1px 2px rgb(45 52 50 / 0.06), 0 4px 12px rgb(45 52 50 / 0.04);
  --radius: 18px;
  font-family: "DM Sans", "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", "Heiti TC",
    ui-sans-serif, system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(1200px 500px at 50% -120px, rgba(95, 127, 121, 0.16), transparent 55%),
    radial-gradient(900px 420px at 110% 10%, rgba(227, 27, 35, 0.06), transparent 50%),
    radial-gradient(800px 380px at -10% 20%, rgba(29, 92, 255, 0.06), transparent 50%),
    var(--bg);
  color: var(--text);
}

body {
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

.landing {
  width: min(1200px, calc(100% - 32px));
  margin: 0 auto;
  padding: 32px 0 48px;
}

.landing-grid,
.host-courts,
.judge-halves,
.score-strip,
.winner-choice {
  display: grid;
  gap: 16px;
}

.landing-grid {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.landing-card,
.panel,
.judge-panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.landing-card,
.panel {
  padding: 20px;
}

.hero {
  margin-bottom: 20px;
}

.eyebrow {
  margin: 0 0 6px;
  color: var(--brand);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

h1,
h2,
.page-title {
  margin: 0;
}

.lead,
.page-subtitle,
.sheet-copy,
.inline-note {
  color: var(--muted);
}

.landing-actions,
.toolbar,
.stack-actions,
.foot-actions,
.host-summary {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.ghost,
.solid,
.ghost-link,
.solid-link,
.wide,
.mini,
.score-button {
  border: 0;
  border-radius: 12px;
  cursor: pointer;
  font-weight: 700;
}

.ghost,
.ghost-link,
.mini {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
}

.solid,
.solid-link,
.score-button {
  background: var(--brand);
  color: #fff;
  /* 綠底白字：略鬆字距，避免漢字筆畫黏在一起 */
  letter-spacing: 0.06em;
  font-feature-settings: "kern" 1;
}

.solid:hover,
.solid-link:hover,
.score-button:hover {
  background: var(--brand-hover);
}

.ghost,
.solid,
.ghost-link,
.solid-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 10px 16px;
}

.wide {
  width: 100%;
}

.feature-list {
  margin: 14px 0 0;
  padding-left: 18px;
  color: var(--muted);
}

.topbar,
.judge-topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  padding: 20px;
}

.workspace {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  gap: 18px;
  padding: 0 20px 24px;
}

.sidebar,
.main-panel {
  display: grid;
  gap: 18px;
  align-content: start;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-size: 13px;
}

.field.compact {
  margin-bottom: 0;
}

.field input,
.field select,
.field textarea,
.link-card textarea {
  width: 100%;
  background: #fff;
  border: 1px solid var(--line);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 12px;
}

.field input::placeholder,
.field textarea::placeholder,
.link-card textarea::placeholder {
  color: #8a9391;
}

.link-list {
  display: grid;
  gap: 12px;
}

.link-card {
  display: grid;
  gap: 8px;
  padding: 12px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.host-summary {
  margin-bottom: 16px;
}

.summary-item {
  flex: 1;
  min-width: 160px;
  padding: 14px 16px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
}

.summary-label {
  display: block;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 6px;
}

.host-courts {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.host-courts[data-count="1"] {
  grid-template-columns: minmax(0, 420px);
}

.host-courts[data-count="2"] {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.qr-block {
  display: grid;
  justify-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 18px 12px;
  border-radius: 16px;
  background: #fff;
  border: 1px dashed var(--line);
}

.qr-block canvas,
.qr-block img,
.qr-image {
  width: 220px;
  height: 220px;
  border-radius: 12px;
  background: #fff;
}

.court-waiting h2 {
  font-size: 22px;
}

.landing-judge-hint {
  margin: 14px 0 0;
}

.exit-projection {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 30;
  min-height: 40px;
  padding: 8px 14px;
  border: 0;
  border-radius: 12px;
  background: rgba(45, 52, 50, 0.82);
  color: #fff;
  font-weight: 800;
  cursor: pointer;
}

body.projection-mode .topbar,
body.projection-mode .sidebar,
body.projection-mode .host-summary,
body.projection-mode .host-only-controls {
  display: none !important;
}

body.projection-mode .workspace {
  grid-template-columns: 1fr;
  padding: 16px;
  min-height: 100vh;
}

body.projection-mode .main-panel {
  gap: 0;
}

body.projection-mode .host-courts {
  min-height: calc(100vh - 32px);
  align-content: stretch;
}

body.projection-mode .court-card {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-height: calc(100vh - 40px);
}

body.projection-mode .fighter-name,
body.projection-mode .round-badge,
body.projection-mode .winner-banner {
  font-size: clamp(28px, 3.2vw, 40px);
}

body.projection-mode .round-dot {
  font-size: clamp(24px, 2.8vw, 34px);
  min-width: 96px;
  padding: 10px 16px;
}

body.projection-mode .score-box strong {
  font-size: clamp(96px, 12vw, 180px);
}

.confirm-panel h2 {
  margin-top: 6px;
}

.confirm-panel .stack-actions {
  margin-top: 18px;
}

.court-card-head,
.judge-header,
.judge-meta {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
}

.court-card-head h2 {
  margin: 0;
}

.court-card h2,
.fighter-name {
  font-size: 24px;
}

.fighter-name {
  margin: 0 0 10px;
  text-align: center;
  line-height: 1.2;
  word-break: break-word;
}

.vs {
  color: var(--muted);
  font-size: 0.8em;
}

.score-strip {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  margin-top: 16px;
}

.score-column {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.score-box,
.judge-side {
  border-radius: 16px;
  padding: 16px;
  color: #fff;
  flex: 1;
}

.score-box.red,
.judge-side.red {
  background: linear-gradient(180deg, var(--red-deep), #2a0709 70%);
}

.score-box.blue,
.judge-side.blue {
  background: linear-gradient(180deg, var(--blue-deep), #071433 70%);
}

.score-box span {
  display: block;
  font-size: 13px;
  color: rgba(255, 255, 255, 0.72);
}

.score-box strong {
  display: block;
  font-size: clamp(64px, 7vw, 110px);
  line-height: 1;
}

.rounds {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  padding: 14px 0 0;
}

.round-dot {
  min-width: 72px;
  text-align: center;
  padding: 6px 8px;
  border-radius: 999px;
  background: var(--panel-2);
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  border: 1px solid var(--line);
}

.court-card .round-dot {
  font-size: 20px;
  min-width: 88px;
  padding: 8px 12px;
}

.round-dot.current {
  color: var(--brand);
  background: var(--brand-subtle);
  border-color: color-mix(in srgb, var(--brand) 28%, var(--line));
}

.round-dot.blue-win {
  color: #1e3a8a;
  background: rgba(29, 92, 255, 0.14);
  border-color: rgba(29, 92, 255, 0.25);
}

.round-dot.red-win {
  color: #9f1239;
  background: rgba(227, 27, 35, 0.12);
  border-color: rgba(227, 27, 35, 0.22);
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 28px;
  font-size: 12px;
  font-weight: 900;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--brand-subtle);
  color: var(--brand);
}

.round-badge {
  font-size: 24px;
  min-height: 40px;
  padding: 6px 14px;
  line-height: 1.2;
}

.badge.done {
  background: color-mix(in srgb, var(--ok) 18%, white);
  color: var(--ok);
}

.winner-banner {
  margin: 8px 0 0;
  text-align: center;
  font-size: 24px;
  font-weight: 900;
  min-height: 28px;
  line-height: 1.2;
}

.court-card .foot-actions {
  margin-top: 20px;
  justify-content: center;
}

.overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(45, 52, 50, 0.45);
  padding: 20px;
  z-index: 20;
}

.overlay.open {
  display: flex;
}

.sheet {
  width: min(420px, 100%);
  background: var(--panel);
  border-radius: 18px;
  padding: 20px;
  border: 1px solid var(--line);
  box-shadow: var(--shadow);
}

.winner-choice {
  grid-template-columns: 1fr;
  margin: 16px 0;
}

.judge-body {
  display: grid;
  grid-template-rows: auto 1fr;
}

.judge-root {
  padding: 0 14px 18px;
}

.judge-panel {
  padding: 12px;
}

.judge-halves {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.judge-side {
  display: grid;
  gap: 8px;
  padding: 12px;
  min-height: 0;
}

.judge-side .field {
  margin: 0;
}

.judge-side-body {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 64px;
  gap: 10px;
  align-items: stretch;
  min-height: 168px;
}

.judge-score {
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  font-size: clamp(56px, 14vw, 120px);
  font-weight: 900;
  line-height: 1;
  margin: 0;
  min-height: 168px;
}

.judge-points {
  display: grid;
  grid-template-rows: repeat(3, minmax(48px, 1fr));
  gap: 12px;
}

.judge-manual input {
  min-height: 40px;
  padding: 6px 10px;
}

.score-button {
  min-height: 68px;
  font-size: clamp(22px, 4vw, 34px);
}

.judge-side .score-button {
  min-height: 48px;
  padding: 0;
  font-size: clamp(18px, 4.5vw, 28px);
  background: #fff;
  color: var(--text);
}

.judge-side .score-button:hover {
  background: var(--brand-subtle);
  color: var(--brand-hover);
}

.judge-side .score-button:disabled,
#btn-end-round:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.judge-footer {
  margin-top: 10px;
  padding: 10px 0 0;
}

.judge-footer .rounds {
  padding-top: 0;
}

.judge-foot-actions {
  display: grid;
  grid-template-columns: 1.2fr 1fr;
  gap: 8px;
  margin-top: 10px;
}

.judge-foot-actions .solid,
.judge-foot-actions .ghost {
  width: 100%;
}

.judge-header {
  margin-bottom: 2px;
}

.judge-sync {
  font-size: 12px;
}

body.judge-live .judge-topbar {
  padding: 10px 14px;
  align-items: flex-start;
}

body.judge-live .eyebrow {
  display: none;
}

body.judge-live .page-title {
  font-size: 16px;
  font-weight: 800;
}

body.judge-live .page-subtitle {
  margin: 2px 0 0;
  font-size: 13px;
}

body.judge-live .ghost-link {
  min-height: 36px;
  padding: 6px 12px;
  font-size: 13px;
}

@media (max-width: 1100px) {
  .workspace,
  .landing-grid,
  .host-courts {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 720px) {
  /* 主控投影端仍可上下堆疊；裁判手機維持左右切分以便同屏計分 */
  .score-strip {
    grid-template-columns: 1fr;
  }

  .judge-root {
    padding: 0 8px 12px;
  }

  .judge-panel {
    padding: 8px;
  }

  .judge-halves {
    gap: 8px;
  }

  .judge-side {
    padding: 10px 8px;
  }

  .judge-side .field {
    font-size: 12px;
  }

  .judge-side .field input {
    min-height: 36px;
    padding: 6px 8px;
    font-size: 14px;
  }

  .judge-side-body {
    grid-template-columns: minmax(0, 1fr) 56px;
    gap: 8px;
    min-height: 180px;
  }

  .judge-score {
    font-size: clamp(48px, 18vw, 72px);
    min-height: 180px;
  }

  .judge-points {
    gap: 14px;
    grid-template-rows: repeat(3, minmax(52px, 1fr));
  }

  .judge-side .score-button {
    min-height: 52px;
    font-size: 20px;
  }
}

/* ========== 歷史紀錄 ========== */
.history-head-actions {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.history-list-card {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  text-align: left;
  padding: 12px;
  border-radius: 14px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: inherit;
  cursor: pointer;
}

.history-list-card:hover {
  border-color: color-mix(in srgb, var(--brand) 45%, var(--line));
  background: color-mix(in srgb, var(--brand-subtle) 70%, white);
}

.history-list-card-main {
  display: grid;
  gap: 4px;
  min-width: 0;
  flex: 1;
}

.history-list-card-action {
  flex-shrink: 0;
  color: var(--brand);
  font-size: 13px;
  font-weight: 700;
  padding-top: 2px;
}

.history-overlay {
  z-index: 30;
  align-items: stretch;
  justify-content: center;
  padding: 24px 16px;
}

.history-sheet {
  position: relative;
  width: min(640px, 100%);
  max-height: min(88vh, 900px);
  overflow: auto;
  padding-top: 48px;
}

.history-close {
  position: absolute;
  top: 14px;
  right: 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}

.history-close:hover {
  color: var(--text);
  border-color: var(--brand);
}

.history-detail {
  display: grid;
  gap: 16px;
}

.history-detail-toolbar {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}

.history-detail-toolbar .danger {
  color: var(--red-deep);
  border-color: color-mix(in srgb, var(--red) 35%, var(--line));
}

.history-detail-hero h2 {
  margin: 4px 0;
  font-size: clamp(24px, 4vw, 32px);
}

.history-section-title {
  margin: 0;
  font-size: 16px;
}

.history-match-list,
.history-round-list {
  display: grid;
  gap: 12px;
}

.history-match-card {
  display: grid;
  gap: 10px;
  width: 100%;
  text-align: left;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: #fff;
  color: inherit;
  cursor: pointer;
}

.history-match-card:hover {
  border-color: color-mix(in srgb, var(--brand) 40%, var(--line));
}

.history-match-card-head,
.history-round-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.history-match-vs {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.history-match-vs-static {
  padding: 4px 0 8px;
}

.history-match-ratio {
  font-size: 20px;
  font-variant-numeric: tabular-nums;
}

.history-side {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  min-width: 0;
}

.history-side-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  flex-shrink: 0;
}

.history-side.red .history-side-dot {
  background: var(--red);
}

.history-side.blue .history-side-dot {
  background: var(--blue);
}

.history-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  background: var(--panel-2);
  color: var(--muted);
}

.history-pill.red {
  background: color-mix(in srgb, var(--red) 14%, white);
  color: var(--red-deep);
}

.history-pill.blue {
  background: color-mix(in srgb, var(--blue) 14%, white);
  color: var(--blue-deep);
}

.history-pill.muted {
  background: var(--panel-2);
  color: var(--muted);
}

.history-round-card {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  background: #fff;
  display: grid;
  gap: 10px;
}

.history-round-score {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
}

.history-round-points {
  display: grid;
  justify-items: center;
  gap: 2px;
  min-width: 64px;
  opacity: 0.55;
}

.history-round-points.won {
  opacity: 1;
}

.history-round-points strong {
  font-size: 28px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
}

.history-workspace {
  grid-template-columns: 1fr;
}

.history-main {
  min-width: 0;
}

.history-page-panel {
  width: min(720px, 100%);
}

.toolbar a.solid,
.toolbar a.ghost,
.toolbar .solid,
.toolbar .ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

@media (max-width: 720px) {
  .history-match-vs {
    flex-direction: column;
    align-items: stretch;
  }

  .history-match-ratio {
    text-align: center;
  }

  .history-sheet {
    width: 100%;
    max-height: 92vh;
  }
}
