/* ============================================================
   截码战 · 记录纸
   ============================================================ */

@font-face {
  font-family: "Silkscreen";
  src: url("./fonts/silkscreen-400.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Silkscreen";
  src: url("./fonts/silkscreen-700.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "Press Start 2P";
  src: url("./fonts/press-start-2p.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ---------- 主题：主题色即队伍颜色 ---------- */
/* 页外背景、斜切块、折角、判定勾、吉祥物取队伍色；卡面保持中性“纸”的配色 */
:root {
  --font-pixel: "Press Start 2P", "Silkscreen", ui-monospace, "Courier New", monospace;
  --font-logo: "Silkscreen", "Press Start 2P", ui-monospace, monospace;
  --font-ui: system-ui, -apple-system, "PingFang SC", "Hiragino Sans GB",
    "Microsoft YaHei", "Segoe UI", sans-serif;

  --box: 42px;
  --radius: 9px;

  /* 卡面配色 */
  --ink: #111111;
  --muted: #8a8a8a;

  /* 卡片永远保持“纸面”配色 */
  --card-bg: #ffffff;
  --card-line: #b5b5b5;
  --card-ink: #111111;
  --head-bg: #d9d9d9;
  --head-line: #cccccc;
  --zebra: #ededed;
  --box-line: #b3b3b3;
  --inside-muted: #b9b9b9;
}

/* 蓝队 */
:root,
html[data-team="blue"] {
  --brand: #2f6bed;
  --body-bg: #16224f;
  --sheet-bg: #f6f8ff;
  --sheet-line: #d9e2ff;
  --bar-bg: rgba(18, 27, 63, 0.9);
  --bar-line: rgba(255, 255, 255, 0.18);
  --page-ink: #f4f7ff;
  --page-muted: rgba(244, 247, 255, 0.68);
  --fold: #2f6bed;
  --ticker: #1d2f6b;
  --ring: #2f6bed;
  --m-body: #cbd9fb;
  --m-screen: #2f6bed;
  --m-line: #14214b;
  --m-face: #ffffff;
}

/* 绿队 */
html[data-team="green"] {
  --brand: #12945a;
  --body-bg: #0d3a27;
  --sheet-bg: #f4fbf6;
  --sheet-line: #d3eedd;
  --bar-bg: rgba(10, 45, 30, 0.9);
  --bar-line: rgba(255, 255, 255, 0.18);
  --page-ink: #f2fbf6;
  --page-muted: rgba(242, 251, 246, 0.68);
  --fold: #12945a;
  --ticker: #124430;
  --ring: #12945a;
  --m-body: #c6ebd5;
  --m-screen: #12945a;
  --m-line: #0b3322;
  --m-face: #ffffff;
}

/* 橙队 */
html[data-team="orange"] {
  --brand: #e2711d;
  --body-bg: #42260e;
  --sheet-bg: #fff8f1;
  --sheet-line: #f7dfc9;
  --bar-bg: rgba(58, 32, 10, 0.9);
  --bar-line: rgba(255, 255, 255, 0.18);
  --page-ink: #fff5ec;
  --page-muted: rgba(255, 245, 236, 0.68);
  --fold: #e2711d;
  --ticker: #4a2810;
  --ring: #e2711d;
  --m-body: #ffd9b6;
  --m-screen: #e2711d;
  --m-line: #3d2309;
  --m-face: #ffffff;
}

/* ---------- 基础 ---------- */
*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  padding: 0 8px calc(env(safe-area-inset-bottom, 0px) + 28px);
  background: var(--body-bg);
  color: var(--page-ink);
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}

button,
input,
select {
  font: inherit;
  color: inherit;
  touch-action: manipulation;
}

:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

/* ---------- 顶栏 ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 30;
  margin: 0 -8px;
  background: var(--bar-bg);
  border-bottom: 1px solid var(--bar-line);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
}

.appbar-in {
  max-width: 940px;
  margin: 0 auto;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 12px 8px;
  display: flex;
  align-items: center;
  gap: 10px;
}

.brand-mini {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: var(--page-ink);
  text-decoration: none;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  flex: none;
}

.mark {
  width: 24px;
  height: 24px;
  display: grid;
  place-items: center;
  border-radius: 5px;
  background: var(--brand);
  color: #ffffff;
  font-family: var(--font-pixel);
  font-size: 12px;
  line-height: 1;
}

.team-switch {
  display: flex;
  gap: 2px;
  padding: 3px;
  border: 1px solid var(--bar-line);
  border-radius: 999px;
  flex: none;
}

.team-tab {
  border: 0;
  border-radius: 999px;
  padding: 0 12px;
  min-height: 32px;
  background: transparent;
  color: var(--page-muted);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.team-tab[aria-selected="true"] {
  background: #ffffff;
  color: var(--brand);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}

.progress {
  margin: 0 0 0 auto;
  font-size: 12px;
  color: var(--page-muted);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.appbar-actions {
  display: flex;
  gap: 6px;
  flex: none;
}

.icon-btn {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid var(--bar-line);
  border-radius: 9px;
  background: transparent;
  color: var(--page-ink);
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.icon-btn:hover {
  background: #ffffff;
  color: var(--ink);
}

.icon-btn:active {
  transform: translateY(1px);
}

/* ---------- 纸面 ---------- */
.sheet {
  max-width: 940px;
  margin: 14px auto 0;
  padding: clamp(14px, 3vw, 26px);
  background: var(--sheet-bg);
  border: 1px solid var(--sheet-line);
  border-radius: 16px;
  color: var(--ink);
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.28), 0 2px 6px rgba(0, 0, 0, 0.16);
}

/* ---------- 页头 ---------- */
.sheet-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
}

.brand {
  --logo-size: clamp(20px, 4.8vw, 34px);
  display: flex;
  align-items: flex-end;
  gap: 0.18em;
  flex: 1 1 auto;
  min-width: 0;
  font-size: var(--logo-size);
}

.logo {
  margin: 0;
  font-family: var(--font-logo);
  font-weight: 700;
  font-size: 1em;
  line-height: 1;
  letter-spacing: 0.045em;
  color: var(--ink);
  white-space: nowrap;
}

/* 吉祥物跟随字号缩放，脚踩在文字基线上，不额外撑高页头 */
.mascot {
  width: auto;
  height: 1.3em;
  flex: none;
  margin-bottom: 0.08em;
}

.name-field {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1 1 250px;
  min-width: 0;
  min-height: 50px;
  padding: 0 10px;
  background: #ffffff;
  border: 2px solid #cfcfcf;
  border-radius: 10px;
}

.name-field:focus-within {
  border-color: #111111;
}

.name-input {
  flex: 1;
  min-width: 0;
  border: 0;
  background: transparent;
  padding: 12px 0;
  font-size: 16px;
  font-weight: 600;
  color: #111111;
  outline: none;
}

.name-input::placeholder {
  color: #b9b9b9;
  font-weight: 400;
}

.robots {
  width: 54px;
  height: 27px;
  flex: none;
}

/* ---------- 说明 ---------- */
.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 14px;
  margin: 12px 0 0;
  font-size: 12px;
  color: var(--muted);
}

.legend b {
  color: var(--ink);
  font-weight: 600;
}

/* ---------- 回合卡 ---------- */
.rounds {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  margin-top: 10px;
}

.card {
  border: 2px solid var(--card-line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--card-ink);
  overflow: hidden;
  break-inside: avoid;
}

.card-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 8px;
  background: var(--head-bg);
  border-bottom: 2px solid var(--head-line);
  color: var(--card-ink);
}

/* 左上角折角 */
.card-head::before {
  content: "";
  position: absolute;
  top: 0;
  left: 0;
  width: 24px;
  height: 22px;
  background: var(--fold);
  clip-path: polygon(0 0, 100% 0, 0 100%);
}

/* 右侧斜切块 */
.card-head::after {
  content: "";
  position: absolute;
  top: 0;
  left: 56%;
  width: 22%;
  height: 100%;
  background: var(--fold);
  clip-path: polygon(0 0, 100% 0, 88% 100%, 28% 100%);
  pointer-events: none;
}

.card-no {
  position: relative;
  z-index: 1;
  font-family: var(--font-pixel);
  font-size: 12px;
  font-weight: 400;
  letter-spacing: 0.04em;
}

.card-flags {
  position: relative;
  z-index: 1;
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 9px;
}

.flag {
  width: 20px;
  height: 20px;
  border: 2px solid transparent;
  border-radius: 3px;
  background: transparent;
  color: #111111;
  display: grid;
  place-items: center;
  font-family: var(--font-pixel);
  font-size: 11px;
  line-height: 1;
}

.flag svg {
  width: 13px;
  height: 13px;
}

.card[data-state="hit"] .flag {
  background: var(--brand);
  border-color: var(--brand);
  color: #ffffff;
}

.card[data-state="miss"] .flag {
  border-color: #111111;
  background: #ffffff;
  color: #111111;
}

.card-info {
  width: 16px;
  height: 16px;
  color: #111111;
  opacity: 0.9;
}

.card-info svg {
  width: 16px;
  height: 16px;
  display: block;
}

/* 列标题 */
.cols {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--box) var(--box);
  gap: 8px;
  padding: 6px 8px 0;
  font-size: 10px;
  letter-spacing: 0.12em;
  color: #969696;
  text-align: center;
}

/* 行 */
.card-rows .row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--box) var(--box);
  gap: 8px;
  align-items: center;
  padding: 6px 8px;
  min-height: 50px;
}

.card-rows .row:nth-child(2) {
  background: var(--zebra);
}

.clue {
  width: 100%;
  min-width: 0;
  border: 0;
  border-radius: 4px;
  background: transparent;
  padding: 10px 2px;
  font-size: 16px;
  line-height: 1.2;
  color: #111111;
  outline: none;
}

.clue::placeholder {
  color: #c0c0c0;
}

.clue:focus-visible {
  outline: 2px solid #111111;
  outline-offset: 0;
}

/* 数字格 */
.num {
  position: relative;
  width: var(--box);
  height: var(--box);
  display: grid;
  place-items: center;
  border: 2px solid var(--box-line);
  border-radius: 4px;
  background: #ffffff;
  overflow: hidden;
}

.num:hover {
  border-color: #8f8f8f;
}

.num-val {
  font-family: var(--font-pixel);
  font-size: 13px;
  line-height: 1;
  color: #111111;
}

.num-val:empty::after {
  content: "·";
  color: #d8d8d8;
  font-size: 16px;
}

.num-select {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  background: transparent;
  cursor: pointer;
  font-size: 16px; /* 防止 iOS 聚焦放大 */
}

.num:focus-within {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

/* 数字重复时的提示动画 */
.num.is-invalid {
  border-color: var(--brand);
  animation: num-shake 0.34s ease;
}

.num.is-invalid .num-val {
  color: var(--brand);
}

@keyframes num-shake {
  0%, 100% { transform: translateX(0); }
  20% { transform: translateX(-3px); }
  40% { transform: translateX(3px); }
  60% { transform: translateX(-2px); }
  80% { transform: translateX(2px); }
}

/* ---------- 关键字 ---------- */
.sec-title {
  margin: 20px 0 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--muted);
}

.kw-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.kw {
  display: flex;
  flex-direction: column;
  min-height: 148px;
  border: 2px solid var(--card-line);
  border-radius: var(--radius);
  background: var(--card-bg);
  color: var(--card-ink);
  overflow: hidden;
  break-inside: avoid;
}

.kw-head {
  position: relative;
  display: flex;
  align-items: center;
  height: 32px;
  padding: 0 9px;
  background: var(--head-bg);
  border-bottom: 2px solid var(--head-line);
  overflow: hidden;
}

.kw-head::after {
  content: "";
  position: absolute;
  top: 0;
  left: 52%;
  width: 44%;
  height: 100%;
  background: var(--fold);
  clip-path: polygon(0 0, 100% 0, 92% 100%, 14% 100%);
  pointer-events: none;
}

.kw-no {
  position: relative;
  z-index: 1;
  font-family: var(--font-pixel);
  font-size: 12px;
  letter-spacing: 0.06em;
}

.kw-body {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  padding: 10px;
}

.kw-input {
  width: 100%;
  border: 0;
  border-bottom: 1px dashed #cfcfcf;
  border-radius: 0;
  background: transparent;
  padding: 6px 2px;
  font-size: 16px;
  font-weight: 600;
  color: #111111;
  outline: none;
}

.kw-input::placeholder {
  color: #c0c0c0;
  font-weight: 400;
}

.kw-input:focus-visible {
  border-bottom-color: #111111;
  outline: 2px solid #111111;
  outline-offset: 2px;
}

.kw-clues {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.kw-clue {
  display: flex;
  gap: 6px;
  align-items: baseline;
  font-size: 12px;
  line-height: 1.35;
}

.kw-clue-r {
  flex: none;
  font-family: var(--font-pixel);
  font-size: 9px;
  color: #a0a0a0;
}

.kw-clue-t {
  color: #333333;
  word-break: break-word;
}

.kw-empty {
  font-size: 11px;
  line-height: 1.6;
  color: #b8b8b8;
}

/* ---------- 页脚滚动条 ---------- */
.ticker {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding-top: 2px;
  overflow: hidden;
  white-space: nowrap;
  font-family: var(--font-pixel);
  font-size: 10px;
  letter-spacing: 0.03em;
  color: var(--ticker);
  opacity: 0.85;
}

.ticker svg {
  width: 14px;
  height: 11px;
  flex: none;
  opacity: 0.9;
}

/* ---------- 对话框 ---------- */
.dialog {
  max-width: min(420px, calc(100vw - 32px));
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--sheet-bg);
  color: var(--ink);
}

.dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
}

.dialog-body {
  padding: 20px;
}

.dialog-title {
  margin: 0 0 8px;
  font-size: 17px;
}

.dialog-text {
  margin: 0 0 18px;
  font-size: 14px;
  line-height: 1.6;
  color: var(--muted);
}

.dialog-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.btn {
  min-height: 42px;
  padding: 0 16px;
  border: 2px solid var(--ink);
  border-radius: 9px;
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}

.btn-danger {
  background: var(--ink);
  color: var(--sheet-bg);
}

.noscript {
  max-width: 940px;
  margin: 14px auto;
  padding: 12px 16px;
  border: 2px solid #111111;
  border-radius: 10px;
  background: #ffffff;
  color: #111111;
  font-size: 14px;
}

/* ---------- 提示条 ---------- */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 18px);
  z-index: 60;
  width: max-content;
  max-width: min(92vw, 380px);
  padding: 10px 14px;
  border: 2px solid var(--brand);
  border-left-width: 8px;
  border-radius: 10px;
  background: #111111;
  color: #ffffff;
  font-size: 13px;
  line-height: 1.45;
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.32);
  opacity: 0;
  transform: translate(-50%, 10px);
  pointer-events: none;
  transition: opacity 0.16s ease, transform 0.16s ease;
}

.toast[hidden] {
  display: none;
}

.toast.is-in {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- 平板 / 桌面 ---------- */
@media (min-width: 760px) {
  :root {
    --box: 40px;
  }

  .rounds {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(4, auto);
    grid-auto-flow: column;
    column-gap: 12px;
  }

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

  .kw {
    min-height: 220px;
  }
}

/* 窄屏：收紧顶栏（三个队伍 + 进度 + 两个按钮要挤进一行） */
@media (max-width: 460px) {
  .brand-text {
    display: none;
  }

  .appbar-in {
    gap: 6px;
    padding-left: 10px;
    padding-right: 10px;
  }

  .progress {
    font-size: 11px;
  }

  .team-switch {
    gap: 1px;
    padding: 2px;
  }

  .team-tab {
    padding: 0 9px;
    min-height: 30px;
    font-size: 12.5px;
  }

  .icon-btn {
    width: 34px;
    height: 34px;
  }

  .icon-btn svg {
    width: 18px;
    height: 18px;
  }
}

@media (max-width: 380px) {
  .brand-mini {
    display: none;
  }
}

/* 桌面：卡片按纸面顺序 01–04 左列、05–08 右列 */
@media (min-width: 760px) {
  .rounds .card:nth-child(1) { grid-area: 1 / 1; }
  .rounds .card:nth-child(2) { grid-area: 2 / 1; }
  .rounds .card:nth-child(3) { grid-area: 3 / 1; }
  .rounds .card:nth-child(4) { grid-area: 4 / 1; }
  .rounds .card:nth-child(5) { grid-area: 1 / 2; }
  .rounds .card:nth-child(6) { grid-area: 2 / 2; }
  .rounds .card:nth-child(7) { grid-area: 3 / 2; }
  .rounds .card:nth-child(8) { grid-area: 4 / 2; }
}

/* ---------- 打印 ---------- */
@media print {
  @page {
    size: A4 portrait;
    margin: 8mm;
  }

  :root,
  html[data-team] {
    --body-bg: #ffffff;
    --sheet-bg: #ffffff;
    --ink: #111111;
    --muted: #777777;
    --brand: #111111;
    --fold: #8f8f8f;
    --ticker: #1a1a1a;
    --m-body: #d9d9d9;
    --m-screen: #7d7d7d;
    --m-line: #111111;
    --m-face: #ffffff;
    --box: 30px;
  }

  html,
  body {
    background: #ffffff !important;
    padding: 0;
  }

  .appbar,
  .legend,
  .dialog,
  .toast,
  .noscript {
    display: none !important;
  }

  .sheet {
    max-width: none;
    margin: 0;
    padding: 0;
    border: 0;
    border-radius: 0;
    box-shadow: none !important;
    color: #111111;
  }

  .sheet-head {
    gap: 6px 12px;
  }

  .brand {
    --logo-size: 30px;
  }

  .name-field {
    min-height: 36px;
  }

  .name-input {
    padding: 8px 0;
  }

  .rounds {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    grid-template-rows: repeat(4, auto);
    grid-auto-flow: column;
    gap: 6px 10px;
  }

  .rounds .card:nth-child(1) { grid-area: 1 / 1; }
  .rounds .card:nth-child(2) { grid-area: 2 / 1; }
  .rounds .card:nth-child(3) { grid-area: 3 / 1; }
  .rounds .card:nth-child(4) { grid-area: 4 / 1; }
  .rounds .card:nth-child(5) { grid-area: 1 / 2; }
  .rounds .card:nth-child(6) { grid-area: 2 / 2; }
  .rounds .card:nth-child(7) { grid-area: 3 / 2; }
  .rounds .card:nth-child(8) { grid-area: 4 / 2; }

  .card {
    break-inside: avoid;
  }

  .card-head {
    height: 26px;
  }

  .cols {
    padding: 4px 8px 0;
    font-size: 9px;
  }

  .card-rows .row {
    min-height: 36px;
    padding: 3px 8px;
  }

  .clue {
    padding: 6px 2px;
    font-size: 14px;
  }

  .sec-title {
    margin: 10px 0 6px;
  }

  .clue,
  .kw-input,
  .num-select {
    color: #111111;
  }

  input::placeholder,
  textarea::placeholder {
    color: transparent !important;
  }

  .num-val:empty::after {
    content: "";
  }

  .kw-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 8px;
  }

  .kw {
    min-height: 110px;
  }

  .kw-body {
    padding: 8px;
  }

  .ticker {
    margin-top: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
  }
}
