/* 和風原木五子棋 Gomoku Stylesheet */
:root {
  --bg-paper: #f4ede1;
  --bg-paper-alt: #ebe0ce;
  --surface: #fbf7f0;
  --surface-strong: #ffffff;
  --wood-light: #e2be87;
  --wood-mid: #c59353;
  --wood-dark: #7a4b25;
  --wood-deep: #4e2d14;
  --ink: #2a211b;
  --ink-muted: #6c5a4b;
  --accent: #b84a39;       /* 朱紅印章色 */
  --accent-hover: #9c3a2b;
  --gold: #c78d2e;
  --green: #3c7a57;
  --border: #dfd1bd;
  --shadow-sm: 0 2px 8px rgba(78, 45, 20, 0.08);
  --shadow-md: 0 10px 28px rgba(78, 45, 20, 0.13);
  --radius: 14px;
  --radius-sm: 9px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  min-height: 100%;
  font-family: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, -apple-system, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 10%, rgba(226, 190, 135, 0.35), transparent 45%),
    radial-gradient(circle at 85% 90%, rgba(197, 147, 83, 0.25), transparent 50%),
    var(--bg-paper);
  line-height: 1.5;
}

.hidden {
  display: none !important;
}

.app-shell {
  max-width: 1220px;
  margin: 0 auto;
  padding: 10px 18px 14px;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---- TOPBAR ---- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 7px 14px;
  background: rgba(251, 247, 240, 0.9);
  backdrop-filter: blur(8px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  user-select: none;
}

.brand-stone {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  display: inline-block;
}

.stone-black-mini {
  background: radial-gradient(circle at 32% 30%, #666, #181818 70%);
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.35);
}

.stone-white-mini {
  background: radial-gradient(circle at 32% 30%, #fff, #dcd5ca 75%);
  border: 1px solid #c9bfb0;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.18);
  margin-left: -6px;
}

.brand-title {
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--wood-deep);
}

.brand-sub {
  font-size: 0.85rem;
  color: var(--ink-muted);
  padding-left: 6px;
  border-left: 1px solid var(--border);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
}

.conn-badge {
  font-size: 0.82rem;
  padding: 5px 10px;
  border-radius: 999px;
  background: var(--bg-paper-alt);
  border: 1px solid var(--border);
  color: var(--ink-muted);
  cursor: pointer;
  user-select: none;
  white-space: nowrap;
}

.conn-badge.online {
  background: #e9f5ee;
  border-color: #b7dec6;
  color: var(--green);
}

.lang-select {
  height: 36px;
  padding: 0 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  outline: none;
  transition: border-color 0.15s, background 0.15s;
}

.lang-select:hover, .lang-select:focus {
  border-color: var(--wood-mid);
  background: var(--bg-paper);
}

.icon-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  cursor: pointer;
  font-size: 1rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.12s, background 0.15s;
}

.icon-btn:hover {
  background: var(--bg-paper-alt);
  transform: translateY(-1px);
}

.profile-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 5px 12px 5px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--ink);
  cursor: pointer;
  font-size: 0.92rem;
  font-weight: 600;
  transition: border-color 0.15s, background 0.15s;
}

.profile-pill:hover {
  border-color: var(--wood-mid);
  background: var(--bg-paper);
}

.avatar-emoji {
  font-size: 1.25rem;
  line-height: 1;
}

/* ---- BUTTONS & INPUTS ---- */
.btn {
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, transform 0.1s, opacity 0.15s, box-shadow 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: linear-gradient(180deg, #8b552a, #6c3e1b);
  color: #fffaf2;
  box-shadow: 0 3px 10px rgba(108, 62, 27, 0.28);
}

.btn-primary:hover:not(:disabled) {
  background: linear-gradient(180deg, #9b6030, #7a4821);
}

.btn-accent {
  background: linear-gradient(180deg, #c65341, var(--accent));
  color: #fff;
  box-shadow: 0 3px 10px rgba(184, 74, 57, 0.28);
}

.btn-accent:hover:not(:disabled) {
  background: linear-gradient(180deg, #d15d4b, var(--accent-hover));
}

.btn-secondary {
  background: var(--bg-paper-alt);
  color: var(--wood-deep);
  border: 1px solid #d4c0a4;
}

.btn-secondary:hover:not(:disabled) {
  background: #e3d3bc;
}

.btn-danger {
  background: #fae8e6;
  color: var(--accent);
  border: 1px solid #ecc2bc;
}

.btn-danger:hover:not(:disabled) {
  background: #f4d6d2;
}

.btn-ghost {
  background: transparent;
  color: var(--ink-muted);
  border: 1px solid var(--border);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-paper-alt);
  color: var(--ink);
}

.btn-block {
  width: 100%;
}

.btn-sm {
  padding: 6px 12px;
  font-size: 0.85rem;
}

.btn-xs {
  padding: 4px 9px;
  font-size: 0.78rem;
}

.danger-text {
  color: var(--accent);
}

.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.form-group label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--ink-muted);
}

.form-row-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.seg-group {
  display: flex;
  background: var(--bg-paper-alt);
  padding: 3px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  gap: 3px;
}

.seg-btn {
  flex: 1;
  border: none;
  background: transparent;
  padding: 7px 6px;
  border-radius: 7px;
  font-size: 0.86rem;
  font-weight: 600;
  color: var(--ink-muted);
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, box-shadow 0.15s;
}

.seg-btn.active {
  background: var(--surface-strong);
  color: var(--wood-deep);
  box-shadow: 0 1px 4px rgba(78, 45, 20, 0.12);
}

.select-input, .text-input {
  width: 100%;
  padding: 8px 11px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-strong);
  color: var(--ink);
  font-family: inherit;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

.select-input:focus, .text-input:focus {
  border-color: var(--wood-mid);
}

.select-sm {
  padding: 6px 8px;
  font-size: 0.84rem;
}

/* ---- LOBBY VIEW ---- */
.lobby-view {
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.hero-banner {
  background: linear-gradient(135deg, #fbf6ed 0%, #f1e4cf 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  box-shadow: var(--shadow-sm);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  flex-wrap: wrap;
}

.hero-text h1 {
  font-size: 1.55rem;
  color: var(--wood-deep);
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.hero-text p {
  font-size: 0.93rem;
  color: var(--ink-muted);
}

.hero-stats-strip {
  display: flex;
  align-items: center;
  gap: 16px;
  background: rgba(255, 255, 255, 0.65);
  border: 1px solid var(--border);
  padding: 10px 16px;
  border-radius: var(--radius-sm);
}

.mini-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 56px;
}

.mini-stat-label {
  font-size: 0.74rem;
  color: var(--ink-muted);
}

.mini-stat strong {
  font-size: 1.15rem;
  color: var(--wood-deep);
}

.mode-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
}

.mode-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  gap: 14px;
  transition: transform 0.16s, box-shadow 0.16s;
}

.mode-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.mode-card-head {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mode-icon {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--bg-paper-alt);
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
}

.mode-card-head h2 {
  font-size: 1.12rem;
  color: var(--wood-deep);
}

.mode-desc {
  font-size: 0.84rem;
  color: var(--ink-muted);
  margin-top: 2px;
}

.match-info-box {
  background: var(--bg-paper);
  border: 1px dashed #d6c3a8;
  border-radius: var(--radius-sm);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
  color: var(--ink-muted);
  margin-top: auto;
}

.queue-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: #fff6e8;
  border: 1px solid #e6c692;
}

.queue-text {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--wood-dark);
  flex: 1;
}

.spinner {
  width: 18px;
  height: 18px;
  border: 2.5px solid #e2c598;
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.divider-or {
  display: flex;
  align-items: center;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.8rem;
}

.divider-or::before, .divider-or::after {
  content: "";
  flex: 1;
  border-bottom: 1px solid var(--border);
}

.divider-or span {
  padding: 0 10px;
}

.join-row {
  display: flex;
  gap: 8px;
}

.room-code-input {
  text-transform: uppercase;
  letter-spacing: 0.18em;
  font-weight: 700;
  text-align: center;
  flex: 1;
}

/* ---- GAME VIEW ---- */
.game-view {
  --board-size: min(100%, 620px, calc(100vh - 180px));
  display: grid;
  grid-template-columns: minmax(0, 1fr) 340px;
  gap: 16px;
  align-items: start;
}

.board-stage {
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}

.board-header-bar, .board-footer-bar {
  width: var(--board-size);
  max-width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.game-badges {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.pill {
  font-size: 0.8rem;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--wood-deep);
}

.pill-rule {
  background: #f3ebe0;
  color: var(--ink-muted);
}

.pill-rule.is-forbidden {
  background: #fdeceb;
  border-color: #eabbb6;
  color: var(--accent);
}

.pill-code {
  background: #fff4df;
  border-color: #e3c188;
  color: var(--wood-dark);
  cursor: pointer;
  letter-spacing: 0.08em;
}

.pill-code:hover {
  background: #fde8c0;
}

.turn-banner {
  font-size: 0.95rem;
  font-weight: 700;
  padding: 5px 14px;
  border-radius: 999px;
  background: var(--wood-deep);
  color: #fffaf2;
  box-shadow: var(--shadow-sm);
}

.turn-banner.turn-white {
  background: var(--surface-strong);
  color: var(--ink);
  border: 1px solid #cfc2ae;
}

.turn-banner.turn-done {
  background: var(--accent);
  color: #fff;
}

.board-frame {
  position: relative;
  width: var(--board-size);
  max-width: 100%;
  aspect-ratio: 1 / 1;
  padding: 10px;
  border-radius: 16px;
  background: linear-gradient(145deg, #9b6434, #6b3f1c);
  box-shadow:
    0 18px 40px rgba(62, 34, 12, 0.28),
    inset 0 1px 2px rgba(255, 232, 198, 0.4);
}

#boardCanvas {
  width: 100%;
  height: 100%;
  display: block;
  border-radius: 8px;
  cursor: pointer;
  touch-action: manipulation;
}

.move-counter {
  font-size: 0.88rem;
  color: var(--ink-muted);
}

.forbidden-legend {
  font-size: 0.82rem;
  color: var(--accent);
  font-weight: 600;
}

.forbidden-x {
  display: inline-block;
  font-weight: 800;
  margin-right: 3px;
}

/* RESULT OVERLAY */
.result-overlay {
  position: absolute;
  inset: 12px;
  border-radius: 8px;
  background: rgba(42, 33, 27, 0.52);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  animation: fadeIn 0.2s ease-out;
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

.result-card {
  background: var(--surface);
  border: 2px solid var(--wood-mid);
  border-radius: var(--radius);
  padding: 24px 28px;
  text-align: center;
  box-shadow: var(--shadow-md);
  max-width: 320px;
  width: 100%;
}

.result-emoji {
  font-size: 2.5rem;
  margin-bottom: 6px;
}

.result-card h2 {
  font-size: 1.35rem;
  color: var(--wood-deep);
}

.result-card p {
  font-size: 0.92rem;
  color: var(--ink-muted);
  margin: 6px 0 18px;
}

.result-actions {
  display: flex;
  gap: 10px;
  justify-content: center;
}

/* ---- SIDEBAR ---- */
.game-sidebar {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.side-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow-sm);
}

.panel-title {
  font-size: 0.84rem;
  font-weight: 700;
  color: var(--wood-dark);
  margin-bottom: 8px;
}

.seats-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.seat-card {
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-strong);
  transition: border-color 0.18s, box-shadow 0.18s, background 0.18s;
}

.seat-card.active-turn {
  border-color: var(--accent);
  background: #fffaf4;
  box-shadow: 0 0 0 3px rgba(184, 74, 57, 0.14);
}

.seat-main {
  display: flex;
  align-items: center;
  gap: 9px;
}

.stone-disc {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex-shrink: 0;
}

.stone-black {
  background: radial-gradient(circle at 32% 30%, #666, #141414 70%);
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
}

.stone-white {
  background: radial-gradient(circle at 32% 30%, #ffffff, #dcd4c8 75%);
  border: 1px solid #c6bba9;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.18);
}

.seat-info {
  flex: 1;
  min-width: 0;
}

.seat-role {
  font-size: 0.72rem;
  color: var(--ink-muted);
}

.seat-name {
  font-size: 0.94rem;
  font-weight: 700;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.timer-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}

.timer-track {
  flex: 1;
  height: 6px;
  border-radius: 999px;
  background: var(--bg-paper-alt);
  overflow: hidden;
}

.timer-fill {
  height: 100%;
  width: 100%;
  background: var(--green);
  border-radius: 999px;
  transition: width 0.15s linear, background 0.2s;
}

.timer-fill.warn {
  background: var(--gold);
}

.timer-fill.danger {
  background: var(--accent);
}

.timer-text {
  font-size: 0.78rem;
  font-weight: 700;
  color: var(--ink-muted);
  min-width: 34px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.host-settings {
  margin-bottom: 10px;
}

.action-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.action-buttons .btn {
  flex: 1;
  min-width: 110px;
}

.online-side-wrap {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.spectator-list {
  font-size: 0.84rem;
  color: var(--ink-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.spectator-chip {
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 9px;
  font-size: 0.8rem;
  color: var(--ink);
}

.chat-panel {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.chat-messages {
  height: clamp(120px, calc(100vh - 500px), 200px);
  overflow-y: auto;
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.84rem;
}

.chat-item {
  word-break: break-word;
}

.chat-item.sys {
  color: var(--wood-dark);
  font-style: italic;
  background: rgba(226, 190, 135, 0.24);
  padding: 3px 7px;
  border-radius: 6px;
}

.chat-sender {
  font-weight: 700;
  margin-right: 5px;
}

.chat-ts {
  font-size: 0.72rem;
  color: var(--ink-muted);
  margin-left: 4px;
}

.chat-form {
  display: flex;
  gap: 6px;
}

.chat-input {
  flex: 1;
  padding: 7px 10px;
  font-size: 0.86rem;
}

/* ---- MODALS ---- */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(42, 33, 27, 0.48);
  backdrop-filter: blur(3px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

.modal-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-wide {
  max-width: 520px;
}

.modal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-head h3 {
  color: var(--wood-deep);
}

.modal-foot {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.modal-foot.space-between {
  justify-content: space-between;
}

.avatar-picker {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.avatar-opt {
  height: 44px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface-strong);
  font-size: 1.35rem;
  cursor: pointer;
  transition: transform 0.12s, border-color 0.15s;
}

.avatar-opt:hover {
  transform: scale(1.06);
}

.avatar-opt.selected {
  border-color: var(--accent);
  background: #fff4ef;
}

.stats-content {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.stats-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  background: var(--bg-paper);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
}

.stats-row strong {
  color: var(--wood-deep);
}

/* ---- TOAST ---- */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--wood-deep);
  color: #fffaf2;
  padding: 10px 18px;
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  box-shadow: var(--shadow-md);
  z-index: 200;
  pointer-events: none;
}

/* ---- RESPONSIVE ---- */
@media (max-width: 960px) {
  .mode-grid {
    grid-template-columns: 1fr;
  }
  .game-view {
    grid-template-columns: 1fr;
  }
  .game-sidebar {
    max-width: 660px;
    width: 100%;
    margin: 0 auto;
  }
}

@media (max-width: 560px) {
  .app-shell {
    padding: 10px;
  }
  .topbar {
    padding: 8px 12px;
  }
  .brand-sub {
    display: none;
  }
  .hero-banner {
    padding: 16px;
  }
  .board-frame {
    padding: 7px;
  }
}
