* {
  box-sizing: border-box;
}

html {
  /* 連打でズームさせない(iPhone対策)。ピンチズームは残す。 */
  touch-action: manipulation;
}

:root {
  --sand: #f6e7c9;
  --sand-deep: #e9d3ac;
  --bark: #5b4636;
  --bark-soft: #7d6450;
  --leaf: #6f9a5c;
  --leaf-deep: #4f7742;
  --berry: #d1685e;
  --cream: #fffaf0;
  --font-rounded: "Zen Maru Gothic", -apple-system, "Hiragino Sans", "Yu Gothic", sans-serif;
}

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-rounded);
  background: var(--sand);
  color: var(--bark);
  padding-bottom: 92px; /* 常時表示フッターの高さぶん確保する */
}

button {
  font-family: inherit;
}

.hidden {
  display: none !important;
}

/* ---- 画面共通 ------------------------------------------------------- */

.screen {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 24px 16px 16px;
}

.panel {
  width: 100%;
  max-width: 640px;
  background: var(--cream);
  border-radius: 24px;
  padding: 24px;
  box-shadow: 0 8px 24px rgba(91, 70, 54, 0.12);
}

.primary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  width: 100%;
  padding: 14px;
  margin-top: 8px;
  border: none;
  border-radius: 999px;
  background: var(--leaf);
  color: #fff;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.primary-button:hover {
  background: var(--leaf-deep);
}

.text-button {
  border: none;
  background: none;
  color: var(--bark-soft);
  font-size: 13px;
  text-decoration: underline;
  cursor: pointer;
  padding: 8px;
}

/* ---- 参加画面 --------------------------------------------------------- */

.join-panel {
  text-align: center;
}

.hero-quokka {
  width: 120px;
  height: 120px;
  margin: 0 auto 8px;
}

.game-title {
  margin: 0 0 4px;
  font-size: 24px;
}

.catch-copy {
  margin: 0 0 20px;
  color: var(--bark-soft);
  font-size: 14px;
}

.field {
  display: block;
  text-align: left;
  margin-bottom: 12px;
}

.field span {
  display: block;
  font-size: 12px;
  color: var(--bark-soft);
  margin-bottom: 4px;
}

.field input {
  width: 100%;
  padding: 10px 12px;
  border: 2px solid var(--sand-deep);
  border-radius: 12px;
  font-size: 16px;
  font-family: inherit;
  background: #fff;
  color: var(--bark);
}

.link-row {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  margin: 16px 0;
}

.rules-link,
.link-row .home-link,
.share-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 5px 12px;
  border: 2px solid var(--sand-deep);
  border-radius: 999px;
  background: #ffffff;
  color: var(--leaf-deep);
  font-size: 12px;
  font-weight: 700;
  font-family: inherit;
  text-decoration: none;
  cursor: pointer;
}

.rules-link:hover,
.link-row .home-link:hover,
.share-button:hover {
  border-color: var(--leaf);
  background: var(--sand);
}

.ranking-panels {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 16px;
}

.ranking-panel {
  background: var(--sand);
  border-radius: 16px;
  padding: 12px;
  text-align: left;
}

.ranking-panel h2 {
  margin: 0 0 6px;
  font-size: 13px;
}

.ranking-list {
  list-style: none;
  margin: 0;
  padding: 0;
  font-size: 12px;
}

.ranking-list li {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  border-bottom: 1px dashed var(--sand-deep);
}

.ranking-list li:last-child {
  border-bottom: none;
}

.ranking-empty {
  color: var(--bark-soft);
  font-size: 12px;
  padding: 4px 0;
}

/* ---- ゲーム画面 ------------------------------------------------------- */

#game-screen {
  max-width: 960px;
  margin: 0 auto;
  width: 100%;
}

.hud {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
  margin-bottom: 12px;
}

.pill {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--cream);
  border: 2px solid var(--sand-deep);
  font-size: 13px;
}

.game-body {
  display: flex;
  gap: 20px;
  align-items: flex-start;
  justify-content: center;
  width: 100%;
}

.board-wrap {
  flex: 1;
  display: flex;
  justify-content: center;
}

.side-panel {
  width: 180px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
}

.mode-toggle {
  width: 100%;
  padding: 12px;
  border: 2px solid var(--leaf);
  border-radius: 999px;
  background: #fff;
  color: var(--leaf-deep);
  font-weight: 700;
  cursor: pointer;
}

.mode-toggle[data-mode="fill"] .mode-mark,
.mode-toggle[data-mode="mark"] .mode-fill {
  display: none;
}

.mode-toggle[data-mode="mark"] {
  border-color: var(--berry);
  color: var(--berry);
}

.quokka-nav {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  width: 100%;
}

.quokka-avatar {
  width: 76px;
  height: 76px;
}

.quokka-bubble {
  position: relative;
  background: #fff;
  border: 2px solid var(--sand-deep);
  border-radius: 16px;
  padding: 8px 12px;
  font-size: 13px;
  text-align: center;
  min-height: 1.4em;
}

.quokka-bubble.pop {
  animation: bubble-pop 0.25s ease-out;
}

@keyframes bubble-pop {
  0% {
    transform: scale(0.9);
  }
  60% {
    transform: scale(1.04);
  }
  100% {
    transform: scale(1);
  }
}

/* ---- 盤面 ------------------------------------------------------------ */

.board-container {
  display: inline-grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  gap: 2px;
  background: var(--sand-deep);
  padding: 2px;
  border-radius: 8px;
  touch-action: none;
  user-select: none;
}

.board-corner {
  grid-column: 1;
  grid-row: 1;
  background: var(--sand);
}

.col-clues {
  grid-column: 2;
  grid-row: 1;
  display: grid;
  grid-auto-flow: column;
  align-items: end;
}

.col-clue {
  display: flex;
  flex-direction: column;
  justify-content: flex-end;
}

.row-clues {
  grid-column: 1;
  grid-row: 2;
  display: grid;
  grid-auto-flow: row;
}

.row-clue {
  display: flex;
  justify-content: flex-end;
}

/* ヒントの数字1個ぶんの正方形。色を塗るマス(.cell)と同じ var(--cell) サイズに揃える。 */
.clue-num {
  width: var(--cell);
  height: var(--cell);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cell) * 0.42);
  line-height: 1;
  background: var(--cream);
  color: var(--bark);
  flex-shrink: 0;
}

.clue-num-blank {
  visibility: hidden;
}

.cells {
  grid-column: 2;
  grid-row: 2;
  display: grid;
}

.cell {
  background: #fff;
  border: 1px solid var(--sand-deep);
}

.cell.filled {
  background: var(--bark);
  border-color: var(--bark);
}

.cell.marked::before,
.cell.marked::after {
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  width: 70%;
  height: 2px;
  background: var(--berry);
}

.cell {
  position: relative;
}

.cell.marked::before {
  transform: translate(-50%, -50%) rotate(45deg);
}

.cell.marked::after {
  transform: translate(-50%, -50%) rotate(-45deg);
}

.cell.block-edge-x {
  border-left-width: 2px;
  border-left-color: var(--bark-soft);
}

.cell.block-edge-y {
  border-top-width: 2px;
  border-top-color: var(--bark-soft);
}

.cell.miss-flash {
  animation: miss-shake 0.3s;
}

@keyframes miss-shake {
  0%,
  100% {
    background: #fff;
  }
  40% {
    background: var(--berry);
  }
}

/* クリア時: ✕を消し、塗ったマスを緑に変えて「絵」として見せる */
.board-container.revealed .cell.filled {
  background: var(--leaf);
  border-color: var(--leaf-deep);
}

.board-container.revealed .cell.marked::before,
.board-container.revealed .cell.marked::after {
  display: none;
}

/* ---- クリア演出 -------------------------------------------------------- */

.overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(91, 70, 54, 0.45);
  padding: 16px;
}

.clear-panel {
  background: var(--cream);
  border-radius: 24px;
  padding: 24px;
  max-width: 420px;
  width: 100%;
  text-align: center;
}

.clear-art {
  display: flex;
  justify-content: center;
  margin-bottom: 12px;
}

.clear-stats {
  display: flex;
  justify-content: center;
  gap: 16px;
  margin: 12px 0;
  font-size: 14px;
}

/* ---- リザルト --------------------------------------------------------- */

.result-panel {
  text-align: center;
}

.result-total {
  font-size: 28px;
  margin: 8px 0;
}

.result-sub {
  color: var(--bark-soft);
  font-size: 13px;
}

.result-stage-list {
  list-style: none;
  margin: 16px 0;
  padding: 0;
  text-align: left;
  font-size: 13px;
}

.result-stage-list li {
  display: flex;
  justify-content: space-between;
  padding: 6px 8px;
  border-bottom: 1px dashed var(--sand-deep);
}

/* ---- サウンドパネル ----------------------------------------------------- */

.sound-controls {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 60;
  display: flex;
  gap: 6px;
}

.sound-toggle-btn,
.sound-settings-btn {
  width: 36px;
  height: 36px;
  border-radius: 999px;
  border: 2px solid var(--sand-deep);
  background: var(--cream);
  font-size: 16px;
  cursor: pointer;
}

.sound-panel {
  position: absolute;
  top: 44px;
  right: 0;
  background: var(--cream);
  border: 2px solid var(--sand-deep);
  border-radius: 16px;
  padding: 12px;
  width: 200px;
  box-shadow: 0 8px 20px rgba(91, 70, 54, 0.15);
}

.sound-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  margin-bottom: 8px;
}

.sound-row:last-child {
  margin-bottom: 0;
}

.sound-row input[type="range"] {
  flex: 1;
}

.mute-chip {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 14px;
}

.sound-row.hide-slider input[type="range"] {
  display: none;
}

/* ---- 常時表示フッター ---------------------------------------------------- */

.site-footer {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 55;
  background: var(--cream);
  border-top: 2px solid var(--sand-deep);
  padding: 6px 12px;
  text-align: center;
  font-size: 11px;
  color: var(--bark-soft);
}

.site-footer a {
  color: var(--bark-soft);
  text-decoration: none;
}

.site-footer a:hover {
  color: var(--leaf-deep);
}

.footer-links,
.footer-meta {
  margin: 2px 0;
}

.version-link {
  font-size: 10px;
  color: var(--text-muted, var(--bark-soft));
  text-decoration: none;
  border-bottom: 1px dotted currentColor;
}

.version-link:hover {
  color: var(--leaf-deep);
}

/* ---- 法務モーダル ------------------------------------------------------- */

.legal-modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.legal-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(91, 70, 54, 0.5);
}

.legal-modal-body {
  position: relative;
  background: var(--cream);
  border-radius: 16px;
  width: 100%;
  max-width: 640px;
  height: 80vh;
  padding: 12px;
}

.legal-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: var(--sand);
  border-radius: 999px;
  width: 32px;
  height: 32px;
  cursor: pointer;
  z-index: 1;
}

.legal-modal-body iframe {
  width: 100%;
  height: 100%;
  border: none;
  border-radius: 10px;
  background: #fff;
}

/* ---- 通信エラー -------------------------------------------------------- */

.disconnect-banner {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(91, 70, 54, 0.9);
  color: #fff;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  text-align: center;
  padding: 24px;
}

.disconnect-banner button {
  padding: 10px 20px;
  border-radius: 999px;
  border: none;
  background: var(--leaf);
  color: #fff;
  cursor: pointer;
}

/* ---- レスポンシブ ------------------------------------------------------- */

@media (max-width: 720px) {
  .game-body {
    flex-direction: column;
    align-items: center;
  }
  .side-panel {
    width: 100%;
    max-width: 320px;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }
  .quokka-nav {
    flex-direction: row;
    width: auto;
  }
  .quokka-avatar {
    width: 56px;
    height: 56px;
  }
}

@media (max-width: 480px) {
  .panel {
    padding: 16px;
  }
  .ranking-panels {
    grid-template-columns: 1fr;
  }
}
