:root {
  --ink: #18342f;
  --muted: #66766f;
  --paper: #f4efe2;
  --paper-light: #fcfaf4;
  --jade: #17695e;
  --jade-dark: #0f4b44;
  --jade-soft: #dce9e4;
  --gold: #bd8d3d;
  --red: #b93a33;
  --red-dark: #842720;
  --black: #252d2b;
  --line: rgba(24, 52, 47, .16);
  --shadow: 0 24px 70px rgba(24, 52, 47, .14);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-height: 100%; background: var(--paper); }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 10% 5%, rgba(255,255,255,.9), transparent 30%),
    radial-gradient(circle at 90% 80%, rgba(23,105,94,.08), transparent 34%),
    linear-gradient(135deg, #f8f4e9, #eee7d7);
  font-family: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

button, input { font: inherit; }
button { color: inherit; }
button:not(:disabled) { cursor: pointer; }
.paper-texture {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .25;
  background-image: url("data:image/svg+xml,%3Csvg width='120' height='120' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.13'/%3E%3C/svg%3E");
}

.topbar {
  position: relative;
  z-index: 10;
  width: min(1180px, calc(100% - 40px));
  margin: 0 auto;
  min-height: 86px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 13px; color: inherit; text-decoration: none; }
.brand-mark { display: grid; grid-template-columns: 1fr 1fr; width: 48px; height: 48px; border-radius: 50%; overflow: hidden; box-shadow: 0 6px 16px rgba(24,52,47,.18); }
.brand-mark i { display: grid; place-items: center; color: #fff; font: 700 18px Georgia, serif; font-style: normal; }
.brand-mark i:first-child { background: var(--red); }
.brand-mark i:last-child { background: var(--black); }
.brand strong { display: block; font-family: "STKaiti", "KaiTi", serif; font-size: 22px; letter-spacing: .08em; }
.brand small { display: block; color: var(--muted); font-size: 11px; letter-spacing: .18em; margin-top: 2px; }
.top-actions { display: flex; gap: 12px; align-items: center; }
.network-state { display: flex; gap: 7px; align-items: center; font-size: 12px; color: var(--muted); }
.network-state i { width: 7px; height: 7px; border-radius: 50%; background: #d79b45; box-shadow: 0 0 0 4px rgba(215,155,69,.13); }
.network-state.online i { background: #35a46a; box-shadow: 0 0 0 4px rgba(53,164,106,.13); }
.network-state.offline i { background: var(--red); box-shadow: 0 0 0 4px rgba(185,58,51,.13); }
.icon-button, .ghost-button, .secondary-button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,.5);
  border-radius: 12px;
  min-height: 42px;
  padding: 0 18px;
  transition: .2s ease;
}
.icon-button:hover, .ghost-button:hover, .secondary-button:hover { background: #fff; border-color: rgba(23,105,94,.35); transform: translateY(-1px); }

.shell { position: relative; z-index: 1; width: min(1180px, calc(100% - 40px)); margin: 0 auto; }
.landing-grid { min-height: calc(100vh - 87px); display: grid; grid-template-columns: 1.1fr .9fr; align-items: center; gap: clamp(48px, 8vw, 110px); padding: 60px 0 86px; }
.eyebrow { display: inline-flex; color: var(--jade); text-transform: uppercase; font-size: 12px; font-weight: 700; letter-spacing: .16em; }
.hero-copy h1 { margin: 22px 0 24px; font-family: "STKaiti", "KaiTi", serif; font-weight: 700; font-size: clamp(54px, 7vw, 92px); line-height: .98; letter-spacing: -.04em; }
.hero-copy h1 em { color: var(--red); font-style: normal; }
.hero-copy > p { max-width: 570px; margin: 0; color: var(--muted); font-size: 18px; line-height: 1.9; }
.rule-chips { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 32px; }
.rule-chips span { padding: 9px 13px; border: 1px solid var(--line); border-radius: 100px; background: rgba(255,255,255,.38); color: #4e625b; font-size: 13px; }

.lobby-card { padding: clamp(28px, 4vw, 45px); background: rgba(252,250,244,.82); border: 1px solid rgba(255,255,255,.85); border-radius: 28px; box-shadow: var(--shadow); backdrop-filter: blur(12px); }
.lobby-heading { display: flex; gap: 15px; align-items: center; margin-bottom: 30px; }
.lobby-heading .seal { width: 52px; height: 52px; display: grid; place-items: center; color: #fff; background: var(--red); border-radius: 15px 15px 15px 4px; font-family: "STKaiti", "KaiTi", serif; font-size: 26px; }
.lobby-heading h2 { margin: 0 0 4px; font-family: "STKaiti", "KaiTi", serif; font-size: 27px; }
.lobby-heading p { margin: 0; color: var(--muted); font-size: 13px; }
.field-label { display: block; margin-bottom: 8px; font-weight: 700; font-size: 13px; }
.text-field { width: 100%; height: 53px; padding: 0 16px; color: var(--ink); background: #fff; border: 1px solid rgba(24,52,47,.18); border-radius: 13px; outline: none; transition: .2s; }
.text-field:focus { border-color: var(--jade); box-shadow: 0 0 0 4px rgba(23,105,94,.1); }
.primary-button { width: 100%; min-height: 54px; border: 0; border-radius: 13px; display: flex; align-items: center; justify-content: space-between; padding: 0 20px; color: #fff; background: linear-gradient(135deg, var(--jade), var(--jade-dark)); box-shadow: 0 10px 24px rgba(15,75,68,.24); font-weight: 700; margin-top: 13px; transition: .2s ease; }
.primary-button:hover { transform: translateY(-2px); box-shadow: 0 14px 28px rgba(15,75,68,.28); }
.primary-button:disabled, .secondary-button:disabled { cursor: wait; opacity: .6; transform: none; }
.primary-button b { font-size: 22px; font-weight: 400; }
.primary-button.small { width: auto; min-height: 43px; margin: 13px auto 0; justify-content: center; padding-inline: 19px; }
.or { display: flex; align-items: center; gap: 12px; margin: 24px 0 16px; color: #87928e; font-size: 11px; }
.or::before, .or::after { content: ""; height: 1px; background: var(--line); flex: 1; }
.join-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.code-field { text-transform: uppercase; font: 700 18px ui-monospace, SFMono-Regular, Consolas, monospace; letter-spacing: .18em; }
.secondary-button { min-height: 53px; padding-inline: 24px; color: var(--jade-dark); font-weight: 700; }
.privacy-note { margin: 19px 0 0; color: #89938f; font-size: 11px; line-height: 1.6; }

.game-view { padding: 34px 0 65px; }
.game-head { display: flex; justify-content: space-between; align-items: end; gap: 20px; margin-bottom: 26px; }
.game-head h2 { margin: 9px 0 4px; font-family: "STKaiti", "KaiTi", serif; font-size: clamp(27px, 4vw, 39px); }
.game-head p { margin: 0; color: var(--muted); font-size: 13px; }
.room-code { border: 0; border-bottom: 1px dashed currentColor; background: none; color: inherit; padding: 0 2px; font: 800 13px ui-monospace, monospace; letter-spacing: .15em; }
.game-head-actions { display: flex; gap: 8px; }
.compact { min-height: 40px; padding-inline: 14px; font-size: 12px; }

.table-layout { display: grid; grid-template-columns: minmax(120px, 1fr) minmax(320px, 590px) minmax(120px, 1fr); align-items: center; gap: clamp(15px, 3vw, 38px); }
.player-panel { position: relative; padding: 22px 18px; min-height: 132px; border: 1px solid var(--line); border-radius: 20px; background: rgba(252,250,244,.65); display: flex; flex-direction: column; text-align: center; align-items: center; justify-content: center; transition: .25s; }
.player-panel::before { content: ""; width: 36px; height: 4px; border-radius: 5px; margin-bottom: 13px; }
.red-panel::before { background: var(--red); }
.black-panel::before { background: var(--black); }
.player-panel .player-color { color: var(--muted); font-size: 11px; letter-spacing: .15em; }
.player-panel strong { max-width: 100%; margin: 6px 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.player-panel > span { color: var(--muted); font-size: 12px; }
.turn-indicator { position: absolute; top: -10px; padding: 5px 10px; border-radius: 100px; color: #fff; background: var(--jade); box-shadow: 0 5px 12px rgba(23,105,94,.2); font-style: normal; font-size: 10px; opacity: 0; transform: translateY(4px); transition: .2s; }
.player-panel.active { border-color: rgba(23,105,94,.5); background: #fff; box-shadow: 0 13px 30px rgba(23,105,94,.1); }
.player-panel.active .turn-indicator { opacity: 1; transform: none; }
.player-panel.you::after { content: "你"; position: absolute; right: 10px; top: 10px; width: 25px; height: 25px; border-radius: 50%; display: grid; place-items: center; color: var(--jade); background: var(--jade-soft); font-size: 10px; font-weight: 700; }

.board-wrap { position: relative; padding: clamp(14px, 2.5vw, 25px); border-radius: 28px; background: linear-gradient(145deg, #7c4d2c, #57311f); box-shadow: 0 28px 60px rgba(65,37,22,.25), inset 0 0 0 1px rgba(255,255,255,.2); }
.board-wrap::before { content: ""; position: absolute; inset: 8px; border: 1px solid rgba(242,198,121,.34); border-radius: 22px; pointer-events: none; }
.board { position: relative; z-index: 1; display: grid; grid-template-columns: repeat(4, 1fr); aspect-ratio: 1; border: 2px solid rgba(51,27,16,.62); background: #c99c65; }
.cell { position: relative; display: grid; place-items: center; min-width: 0; border: 0; border-right: 1px solid rgba(74,42,23,.42); border-bottom: 1px solid rgba(74,42,23,.42); background: linear-gradient(135deg, rgba(255,255,255,.06), rgba(66,35,20,.04)); }
.cell:nth-child(4n) { border-right: 0; }
.cell:nth-child(n+13) { border-bottom: 0; }
.cell::after { content: ""; position: absolute; inset: 7%; border-radius: 16%; border: 2px solid transparent; transition: .18s; }
.cell.is-target::after { border-color: rgba(255,245,188,.9); box-shadow: inset 0 0 0 3px rgba(23,105,94,.35); }
.cell:hover::after { background: rgba(255,255,255,.08); }
.piece { position: relative; width: 72%; aspect-ratio: 1; border-radius: 50%; display: grid; place-items: center; font: 800 clamp(25px, 5vw, 50px) Georgia, "Times New Roman", serif; transition: transform .18s, box-shadow .18s; user-select: none; }
.cell:hover .piece { transform: translateY(-2px); }
.piece.red { color: #fff2e8; background: radial-gradient(circle at 35% 28%, #d45c50, var(--red-dark) 72%); border: clamp(3px, .5vw, 6px) double #f3c29b; box-shadow: 0 7px 12px rgba(93,28,23,.36), inset 0 2px 3px rgba(255,255,255,.24); }
.piece.black { color: #f7e4b9; background: radial-gradient(circle at 35% 28%, #4d5754, #171d1b 72%); border: clamp(3px, .5vw, 6px) double #c4a56e; box-shadow: 0 7px 12px rgba(20,25,23,.42), inset 0 2px 3px rgba(255,255,255,.18); }
.piece.covered { border-radius: 17%; color: rgba(247,230,182,.82); background: linear-gradient(145deg, #237a6e, #0e5048); border: clamp(3px, .5vw, 6px) double rgba(231,212,155,.78); box-shadow: 0 7px 13px rgba(17,65,58,.38), inset 0 0 0 4px rgba(0,0,0,.08); }
.piece.covered::before { content: "數"; font-family: "STKaiti", "KaiTi", serif; font-size: .56em; border: 1px solid rgba(245,225,164,.52); width: 51%; aspect-ratio: 1; display: grid; place-items: center; transform: rotate(45deg); }
.piece.covered::after { content: ""; position: absolute; inset: 13%; border: 1px solid rgba(245,225,164,.25); border-radius: 10%; }
.piece.covered::before { text-orientation: upright; }
.cell.selected .piece { transform: translateY(-5px) scale(1.04); box-shadow: 0 0 0 4px #fff0ad, 0 10px 18px rgba(35,23,12,.4); }
.board-footer { position: relative; z-index: 1; display: flex; justify-content: space-between; align-items: center; color: rgba(255,244,220,.85); font-size: 11px; padding: 14px 4px 0; }
.turn-badge { padding: 5px 9px; color: #352313; background: #e9c884; border-radius: 100px; font-weight: 800; }
.waiting-curtain { position: absolute; z-index: 4; inset: clamp(14px, 2.5vw, 25px); bottom: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; color: #fff7e8; background: rgba(14,58,52,.9); border-radius: 4px; backdrop-filter: blur(5px); }
.waiting-curtain[hidden] { display: none; }
.waiting-stamp { width: 65px; height: 65px; display: grid; place-items: center; margin-bottom: 15px; border: 2px solid #e7bd6f; color: #e7bd6f; font: 33px "STKaiti", serif; transform: rotate(-4deg); }
.waiting-curtain strong { font-size: 19px; }
.waiting-curtain p { color: rgba(255,255,255,.7); margin: 9px 0; font-size: 12px; }
.waiting-curtain p button { color: #f3d89c; border: 0; border-bottom: 1px dashed currentColor; background: none; font: 800 14px ui-monospace, monospace; letter-spacing: .14em; }

.game-info-grid { display: grid; grid-template-columns: 1fr 1fr auto; gap: 12px; margin-top: 20px; }
.action-card { min-height: 79px; padding: 16px 18px; border: 1px solid var(--line); background: rgba(252,250,244,.65); border-radius: 15px; }
.action-card span { display: block; color: var(--muted); font-size: 10px; letter-spacing: .12em; margin-bottom: 7px; }
.action-card strong { font-size: 13px; line-height: 1.5; }
.hint-card { border-color: rgba(23,105,94,.26); }
.resign-button { border: 1px solid rgba(185,58,51,.28); background: rgba(185,58,51,.06); color: var(--red); border-radius: 15px; padding-inline: 18px; font-weight: 700; font-size: 12px; }

dialog { color: var(--ink); border: 0; box-shadow: 0 30px 90px rgba(18,47,42,.35); }
dialog::backdrop { background: rgba(11,30,27,.53); backdrop-filter: blur(4px); }
.rules-dialog { width: min(610px, calc(100% - 28px)); padding: clamp(27px, 5vw, 46px); border-radius: 25px; background: var(--paper-light); }
.rules-dialog h2 { font-family: "STKaiti", "KaiTi", serif; font-size: 31px; margin: 10px 0 25px; }
.dialog-close { position: absolute; right: 16px; top: 14px; width: 36px; height: 36px; border: 0; border-radius: 50%; background: rgba(24,52,47,.07); font-size: 24px; }
.rules-dialog ol { padding: 0; margin: 0; list-style: none; counter-reset: rules; display: grid; gap: 17px; }
.rules-dialog li { counter-increment: rules; display: grid; grid-template-columns: 36px 105px 1fr; gap: 9px; align-items: start; }
.rules-dialog li::before { content: counter(rules); width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; color: #fff; background: var(--jade); font: 700 13px Georgia, serif; }
.rules-dialog li b { font-size: 14px; padding-top: 4px; }
.rules-dialog li span { color: var(--muted); font-size: 13px; line-height: 1.7; }
.win-rule { display: flex; align-items: center; gap: 14px; border-top: 1px solid var(--line); padding-top: 21px; margin-top: 25px; }
.win-rule i { width: 48px; height: 48px; display: grid; place-items: center; flex: none; color: #fff; background: var(--red); border-radius: 50%; font: 24px "STKaiti", serif; font-style: normal; }
.win-rule p { margin: 0; color: var(--muted); font-size: 12px; line-height: 1.65; }
.win-rule strong { color: var(--ink); font-size: 14px; }
.confirm-dialog { width: min(420px, calc(100% - 30px)); padding: 30px; border-radius: 20px; background: var(--paper-light); }
.confirm-dialog h2 { margin: 0 0 8px; font-family: "STKaiti", serif; }
.confirm-dialog p { color: var(--muted); }
.confirm-dialog > div { display: flex; justify-content: end; gap: 9px; margin-top: 24px; }
.danger-button { border: 0; min-height: 42px; padding: 0 18px; border-radius: 12px; color: #fff; background: var(--red); font-weight: 700; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: max(25px, env(safe-area-inset-bottom)); max-width: calc(100% - 30px); padding: 12px 18px; border-radius: 12px; color: #fff; background: rgba(17,43,39,.94); box-shadow: 0 10px 30px rgba(0,0,0,.2); font-size: 13px; opacity: 0; transform: translate(-50%, 15px); pointer-events: none; transition: .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 820px) {
  .landing-grid { grid-template-columns: 1fr; gap: 38px; padding-top: 45px; }
  .hero-copy { text-align: center; }
  .hero-copy > p { margin-inline: auto; }
  .rule-chips { justify-content: center; }
  .table-layout { grid-template-columns: 1fr 1fr; }
  .board-wrap { grid-column: 1 / -1; grid-row: 1; width: min(100%, 590px); justify-self: center; }
  .player-panel { grid-row: 2; min-height: 98px; padding: 17px 12px; }
  .game-info-grid { grid-template-columns: 1fr 1fr; }
  .resign-button { grid-column: 1 / -1; min-height: 46px; }
}

@media (max-width: 560px) {
  .topbar, .shell { width: min(100% - 24px, 1180px); }
  .topbar { min-height: 70px; }
  .brand-mark { width: 41px; height: 41px; }
  .brand strong { font-size: 19px; }
  .brand small, .network-state span { display: none; }
  .icon-button { min-height: 38px; padding-inline: 13px; }
  .landing-grid { min-height: calc(100vh - 70px); padding: 32px 0 55px; }
  .hero-copy h1 { font-size: clamp(48px, 16vw, 70px); margin: 15px 0 17px; }
  .hero-copy > p { font-size: 15px; line-height: 1.75; }
  .rule-chips { margin-top: 22px; }
  .lobby-card { border-radius: 22px; }
  .game-view { padding-top: 21px; }
  .game-head { display: block; }
  .game-head-actions { margin-top: 15px; }
  .board-wrap { padding: 14px; border-radius: 20px; }
  .piece { width: 76%; font-size: clamp(25px, 11vw, 42px); }
  .board-footer { padding-top: 11px; }
  .player-panel { border-radius: 14px; }
  .game-info-grid { grid-template-columns: 1fr; }
  .resign-button { grid-column: auto; }
  .rules-dialog li { grid-template-columns: 32px 1fr; }
  .rules-dialog li span { grid-column: 2; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; animation-duration: .01ms !important; }
}

