:root {
  --bg: #fff8f0;
  --panel: #ffffff;
  --ink: #3a2e2a;
  --accent: #e8734a;
  --accent-dark: #c85a34;
  --blue: #2563eb;
  --red: #dc2626;
  --muted: #8a7a72;
  --line: #f0e2d4;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: "Hiragino Maru Gothic ProN", "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.6;
}

.site-header {
  text-align: center;
  padding: 1.2rem 1rem 0.4rem;
}

.site-header h1 { margin: 0; font-size: 1.8rem; }
.site-header .subtitle { font-size: 1rem; color: var(--accent-dark); }
.lead { font-size: 0.95rem; margin: 0 0 0.6rem; }

main { max-width: 1080px; margin: 0 auto; padding: 0.6rem 1rem 3rem; }

.view.hidden, .hidden { display: none !important; }

.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 1rem 1.2rem;
  margin: 0.8rem 0;
}

.panel.inner { background: #fffdf9; }

h2 { font-size: 1.15rem; margin: 0.4rem 0 0.6rem; }
h3 { font-size: 1rem; margin: 0.8rem 0 0.4rem; }

.mode-select { border: 1px solid var(--line); border-radius: 10px; padding: 0.6rem 1rem; }
.mode-select label { display: block; margin: 0.3rem 0; }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.8rem; }
@media (max-width: 760px) { .grid2 { grid-template-columns: 1fr; } }

.name-row { display: flex; align-items: center; gap: 0.5rem; margin: 0.4rem 0; }
.name-row input { flex: 1; }

input[type="text"], input:not([type]), .code-input {
  padding: 0.45rem 0.6rem;
  border: 2px solid var(--line);
  border-radius: 8px;
  font-size: 1rem;
  max-width: 100%;
}
input { font-family: inherit; }
.code-input { text-transform: uppercase; letter-spacing: 0.2em; width: 12em; }

button {
  font-family: inherit;
  font-size: 1rem;
  padding: 0.5rem 1.1rem;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  cursor: pointer;
}
button:hover:not(:disabled) { background: var(--accent-dark); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.ghost { background: #fff; color: var(--ink); border: 2px solid var(--line); }
button.small { font-size: 0.85rem; padding: 0.3rem 0.8rem; }

.btn-row { display: flex; flex-wrap: wrap; gap: 0.6rem; margin: 0.7rem 0; align-items: center; }

.note { color: var(--muted); font-size: 0.85rem; }

.room-code-box { text-align: center; margin: 1rem 0; }
.room-code-label { font-size: 0.85rem; color: var(--muted); }
.room-code {
  font-size: 2.6rem;
  font-weight: bold;
  letter-spacing: 0.35em;
  color: var(--accent-dark);
  margin: 0.2rem 0 0.6rem;
}
.share-row { display: flex; gap: 0.5rem; justify-content: center; flex-wrap: wrap; }
.share-link { word-break: break-all; font-size: 0.8rem; background: #fff5ec; padding: 0.5rem; border-radius: 8px; }

.game-bar {
  display: flex; flex-wrap: wrap; gap: 0.6rem; align-items: center;
  background: var(--panel); border: 2px solid var(--line); border-radius: 12px;
  padding: 0.5rem 0.9rem; margin: 0.6rem 0; font-size: 0.9rem;
}
.game-bar #conn-status { margin-left: auto; }

.game-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px minmax(0, 1fr); gap: 0.6rem; align-items: start; }
@media (max-width: 1023px) {
  .game-layout { grid-template-columns: 1fr; }
  .center-panel { order: -1; }
}
body[data-screen="game"] main { max-width: 1440px; padding-bottom: 1rem; }
body[data-screen="game"] .site-header,
body[data-screen="game"] .site-footer { display: none; }

.board { text-align: center; }
.board svg { width: min(100%, 260px); height: auto; }
.cell { fill: #fff3e6; stroke: var(--accent); stroke-width: 1.5; }
.cell.start { fill: #ffe0c7; }
.cell-num { font-size: 10px; text-anchor: middle; fill: var(--ink); }
.token-sm { font-size: 12px; text-anchor: middle; }
.board-legend { display: flex; flex-direction: column; gap: 0.2rem; font-size: 0.9rem; margin-top: 0.4rem; }
.dot { display: inline-block; width: 0.8em; height: 0.8em; border-radius: 50%; margin-right: 0.3em; }

.card-row { display: flex; flex-wrap: wrap; gap: 0.5rem; min-height: 3rem; }
.empty { color: var(--muted); font-size: 0.85rem; }

.card {
  position: relative;
  width: 128px;
  height: 152px;
  display: flex;
  flex-direction: column;
  border: 2px solid var(--line);
  border-radius: 10px;
  padding: 0.4rem 0.5rem;
  background: #fffdf8;
  font-size: 0.75rem;
}
.card .tiers { margin-top: auto; }
.card.back { justify-content: center; }
.card.selected { border-color: var(--accent); box-shadow: 0 0 0 3px #f6c9ae; }
.card.faceup { border-color: var(--accent-dark); }
.card.back { background: repeating-linear-gradient(45deg, #f6e3d0, #f6e3d0 8px, #efd5bc 8px, #efd5bc 16px); text-align: center; }
.card.small { width: 64px; height: 84px; }
.card-emoji { font-size: 1.5rem; text-align: center; }
.card-name { font-weight: bold; text-align: center; margin: 0.1rem 0 0.3rem; font-size: 0.85rem; }
.tier { display: flex; justify-content: space-between; gap: 0.3rem; border-top: 1px dashed var(--line); padding: 0.1rem 0; }
.tier.hot { background: #fff0df; font-weight: bold; }
.owned {
  position: absolute; top: -10px; right: -6px;
  background: var(--accent); color: #fff; font-weight: bold;
  border-radius: 999px; padding: 0 0.5em; font-size: 0.8rem;
}
.faceup-mark { text-align: center; color: var(--accent-dark); font-weight: bold; }

button.hand-card { background: none; color: var(--ink); padding: 0; border-radius: 10px; text-align: inherit; }
button.hand-card .card { width: 140px; }
button.hand-card.locked { cursor: default; }
.pick-mark { font-size: 0.8rem; font-weight: bold; color: var(--accent-dark); }

.turn-banner { font-weight: bold; font-size: 1.05rem; margin: 0.3rem 0; }
.sel-info { margin: 0.3rem 0; }
.faceup-row { margin: 0.4rem 0; display: flex; gap: 0.5rem; align-items: center; }
.faceup-row button { background: #fff; color: var(--ink); border: 2px solid var(--line); }
.faceup-row button.on { border-color: var(--accent-dark); background: #fff0df; font-weight: bold; }

.pending-row { display: flex; gap: 1rem; margin: 0.6rem 0; flex-wrap: wrap; }
.pending-label { font-weight: bold; text-align: center; }

.log {
  max-height: 220px; overflow-y: auto;
  background: #fffdf9; border: 1px solid var(--line); border-radius: 8px;
  padding: 0.5rem 0.5rem 0.5rem 1.6rem; font-size: 0.82rem; margin: 0.4rem 0;
}
.log li { margin-bottom: 0.25rem; }
.hash { font-size: 0.7rem; color: var(--muted); }

.modal {
  position: fixed; inset: 0; background: rgba(58, 46, 42, 0.55);
  display: flex; align-items: center; justify-content: center; padding: 1rem; z-index: 50;
}
.modal-box {
  background: #fff; border-radius: 16px; padding: 1.5rem 2rem;
  max-width: 480px; width: 100%; text-align: center;
}
.modal-box .btn-row { justify-content: center; }

.toast {
  position: fixed; left: 50%; bottom: 1.2rem; transform: translateX(-50%);
  background: var(--ink); color: #fff; padding: 0.6rem 1.2rem; border-radius: 999px;
  max-width: 90vw; z-index: 60; font-size: 0.9rem;
}

.site-footer { text-align: center; color: var(--muted); font-size: 0.75rem; padding: 1rem; }

.version-error {
  background: #b3261e; color: #fff; font-weight: bold;
  padding: 0.8rem 1.2rem; text-align: center;
}

/* ゲーム画面のコンパクト表示 */
.game-bar { font-size: 0.85rem; padding: 0.4rem 0.7rem; }
.turn-banner.center { text-align: center; }
.controls:empty { display: none; }
.controls { margin-top: 0.5rem; }
.controls .btn-row { margin: 0.4rem 0; }
.subhead { font-size: 0.8rem; color: var(--muted); font-weight: bold; margin: 0.4rem 0 0.2rem; }
.note.inline { font-weight: normal; }
.player-panel h2 { font-size: 1rem; margin: 0.2rem 0 0.4rem; }
.player-panel .card { width: 102px; height: 132px; font-size: 0.68rem; padding: 0.3rem 0.4rem; }
.player-panel button.hand-card .card { width: 110px; }
.player-panel .card-emoji { font-size: 1.2rem; }
.player-panel .card-name { font-size: 0.75rem; }
.card-row.scroll { max-height: 26vh; overflow-y: auto; }
.center-panel { text-align: center; }
#phase-sub .pending-row { justify-content: center; }
#phase-sub .card { width: 118px; height: 140px; }
.modal-box.wide { max-width: 640px; text-align: left; }
.modal-box.wide h2 { text-align: center; }
.log.tall { max-height: 60vh; }
.btn-row.center { justify-content: center; }

/* ルール表・カード一覧 */
.rule-table { border-collapse: collapse; width: 100%; font-size: 0.85rem; margin: 0.5rem 0; }
.rule-table th, .rule-table td { border: 1px solid var(--line); padding: 0.3rem 0.5rem; text-align: center; }
.rule-table th { background: #fff0df; }
.rule-table td:first-child { text-align: left; white-space: nowrap; }
#rules h4 { margin: 0.9rem 0 0.3rem; font-size: 0.95rem; }
.deck-row { display: flex; gap: 0.6rem; align-items: center; border-bottom: 1px dashed var(--line); padding: 0.4rem 0; }
.deck-emoji { font-size: 1.6rem; }
.deck-name { font-weight: bold; }
.deck-tiers { font-size: 0.82rem; }

/* 公開アニメーション */
.reveal-card { position: relative; perspective: 500px; }
.reveal-card.dimmed { opacity: 0.45; }
.reveal-card.taken .card { animation: taken-pulse 0.55s ease-in-out 2; }
.reveal-card.flip .card { animation: flip-in 0.6s ease, reveal-glow 1.2s ease; }
.taken-badge {
  position: absolute; top: -12px; left: 50%; transform: translateX(-50%);
  background: #ffd54a; color: #5d3a00; font-weight: bold; font-size: 0.8rem;
  border-radius: 999px; padding: 0 0.7em; white-space: nowrap;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
@keyframes taken-pulse {
  0%, 100% { box-shadow: 0 0 0 3px #ffd54a; transform: scale(1); }
  50% { box-shadow: 0 0 22px 8px #ffd54a; transform: scale(1.07); }
}
@keyframes flip-in {
  from { transform: rotateY(90deg) scale(0.92); }
  to { transform: rotateY(0) scale(1); }
}
@keyframes reveal-glow {
  0%, 100% { box-shadow: 0 0 0 3px #ffd54a; }
  50% { box-shadow: 0 0 26px 10px #ffb300; }
}
@media (prefers-reduced-motion: reduce) {
  .reveal-card.taken .card, .reveal-card.flip .card { animation: none; }
}
