:root {
  --bg: #faf7ff;
  --cream: #fffdfb;
  --panel: #ffffff;
  --border: #eadffb;
  --text: #443a5c;
  --muted: #a597bd;
  --accent: #7c6cf0;
  --accent-2: #5d4fe0;
  --board-bg: #20263a;
  --board-line: rgba(255, 255, 255, 0.07);

  --c-I: #3ec6f2;
  --c-O: #f7c948;
  --c-T: #b07ae6;
  --c-S: #4fd08c;
  --c-Z: #f2695c;
  --c-J: #5a8bf5;
  --c-L: #f59a4a;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  min-height: 100%;
}

body {
  background-color: var(--bg);
  background-image: linear-gradient(rgba(26, 18, 48, 0.74), rgba(26, 18, 48, 0.8)), url('assets/img/bg.png');
  background-size: cover;
  background-attachment: fixed;
  color: var(--text);
  font-family: "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
  line-height: 1.6;
}

.site-header {
  position: relative;
  text-align: center;
  padding: 30px 16px 6px;
}

.lang-select {
  position: absolute;
  top: 12px;
  right: 14px;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: #fff;
  color: var(--text);
  font-size: 0.85rem;
  font-family: inherit;
}

.site-header h1 {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: 0.04em;
  color: var(--accent-2);
}

.logo {
  display: inline-grid;
  width: 30px;
  height: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 30 30'%3E%3Crect x='1' y='6' width='9' height='9' rx='2.5' fill='%23b07ae6'/%3E%3Crect x='11' y='6' width='9' height='9' rx='2.5' fill='%23b07ae6'/%3E%3Crect x='21' y='6' width='9' height='9' rx='2.5' fill='%23b07ae6'/%3E%3Crect x='11' y='16' width='9' height='9' rx='2.5' fill='%23b07ae6'/%3E%3C/svg%3E");
  background-size: contain;
  background-repeat: no-repeat;
  margin-right: 8px;
  vertical-align: -6px;
}

.site-header .sub {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.95rem;
}

main {
  max-width: 660px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 22px;
  box-shadow: 0 10px 28px rgba(124, 108, 240, 0.14);
  padding: 16px;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-bottom: 12px;
}

button {
  font-family: inherit;
  font-size: 0.9rem;
  color: var(--text);
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 14px;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.06s ease, background 0.15s ease, box-shadow 0.15s ease;
}

button:hover { background: #f4efff; }
button:active { transform: scale(0.96); }
button.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #fff;
  border: none;
  box-shadow: 0 6px 16px rgba(124, 108, 240, 0.35);
  font-weight: bold;
  padding: 12px 28px;
}
button.primary:hover { filter: brightness(1.06); }

.game-area {
  display: flex;
  justify-content: center;
  align-items: flex-start;
  gap: 18px;
}

.board-wrap {
  position: relative;
  width: min(62vw, 44vh, 360px);
  flex: none;
}

.board {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  grid-template-rows: repeat(20, 1fr);
  aspect-ratio: 1 / 2;
  width: 100%;
  background: var(--board-bg);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: inset 0 0 0 4px rgba(255,255,255,0.06), 0 8px 22px rgba(32, 38, 58, 0.35);
}

.cell {
  border: 1px solid var(--board-line);
  border-radius: 2px;
  transition: background 0.08s ease;
}

.cell.filled {
  border-radius: 4px;
  border: 1px solid rgba(0, 0, 0, 0.18);
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.32),
    inset -3px -3px 0 rgba(0, 0, 0, 0.28);
}

.cell.ghost {
  background: rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.32);
  border-color: transparent;
  border-radius: 4px;
}

.cell.clearing {
  animation: clearflash 0.28s ease-out forwards;
}

@keyframes clearflash {
  0%   { transform: scale(1);    filter: brightness(1);   opacity: 1; }
  45%  { transform: scale(1.15); filter: brightness(2.4); opacity: 1; }
  100% { transform: scale(0.7);  filter: brightness(3);   opacity: 0.15; }
}

.p-I { background: var(--c-I); }
.p-O { background: var(--c-O); }
.p-T { background: var(--c-T); }
.p-S { background: var(--c-S); }
.p-Z { background: var(--c-Z); }
.p-J { background: var(--c-J); }
.p-L { background: var(--c-L); }

.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(24, 28, 44, 0.62);
  backdrop-filter: blur(2px);
  border-radius: 10px;
  z-index: 5;
}

.overlay.hidden { display: none; }

.overlay-box {
  background: var(--cream);
  border-radius: 18px;
  padding: 22px 24px;
  margin: 16px;
  max-width: 320px;
  text-align: center;
  box-shadow: 0 14px 34px rgba(0, 0, 0, 0.35);
}

.overlay-box h2 {
  margin: 0 0 8px;
  color: var(--accent-2);
  font-size: 1.35rem;
}

.overlay-box p {
  margin: 0 0 16px;
  font-size: 0.88rem;
  color: var(--muted);
  white-space: normal;
}

.side {
  width: 190px;
  flex: none;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stat-block {
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 14px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

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

.stat-block b {
  font-size: 1.15rem;
  color: var(--text);
}

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

.stat-row > div {
  flex: 1;
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 8px 10px;
  display: flex;
  flex-direction: column;
}

.stat-row b {
  font-size: 1.05rem;
  color: var(--text);
}

.combo {
  background: linear-gradient(135deg, #ffb84d, #ff8a4d);
  color: #fff;
  font-weight: bold;
  font-size: 0.85rem;
  text-align: center;
  border-radius: 999px;
  padding: 4px 10px;
  box-shadow: 0 4px 12px rgba(255, 138, 77, 0.4);
  animation: pop 0.2s ease;
}

.combo.hidden { display: none; }

@keyframes pop {
  0% { transform: scale(0.7); }
  70% { transform: scale(1.1); }
  100% { transform: scale(1); }
}

.preview {
  background: var(--cream);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 12px;
}

.preview .stat-label {
  display: block;
  margin-bottom: 8px;
}

.mini-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  width: 64px;
}

.mini {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 2px;
  width: 34px;
}

.mini-cell {
  aspect-ratio: 1;
  border-radius: 2px;
  background: rgba(124, 108, 240, 0.1);
}

.mini-cell.filled {
  border-radius: 3px;
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.35),
    inset -1px -1px 0 rgba(0, 0, 0, 0.25);
}

/* ネクスト／ホールドのミニコマにも各ピースの色を付ける */
.mini-cell.filled.p-I { background: var(--c-I); }
.mini-cell.filled.p-O { background: var(--c-O); }
.mini-cell.filled.p-T { background: var(--c-T); }
.mini-cell.filled.p-S { background: var(--c-S); }
.mini-cell.filled.p-Z { background: var(--c-Z); }
.mini-cell.filled.p-J { background: var(--c-J); }
.mini-cell.filled.p-L { background: var(--c-L); }

.next-grid {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mini-grid.unavailable { opacity: 0.35; }

.touch-controls {
  display: none;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
  margin-top: 14px;
}

.touch-controls button {
  min-height: 52px;
  font-size: 0.82rem;
  line-height: 1.15;
  border-radius: 14px;
  user-select: none;
  -webkit-user-select: none;
}

.touch-controls button small {
  color: var(--muted);
  font-size: 0.68rem;
}

.help {
  margin: 16px 2px 2px;
  font-size: 0.78rem;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 620px), (max-height: 500px) {
  html, body { height: 100%; }

  body {
    overflow: hidden;
    display: flex;
    flex-direction: column;
    overscroll-behavior: none;
  }

  a[href="https://ai.noela.moe/"] {
    top: 6px;
    left: 6px;
    font-size: 0.68rem;
    padding: 3px 9px;
  }

  /* スマホではヘッダーを極小化して1画面に収める */
  .site-header {
    flex: none;
    padding: 24px 12px 2px;
  }

  .site-header h1 {
    font-size: 1rem;
  }

  .site-header .sub {
    display: none;
  }

  .logo {
    width: 22px;
    height: 22px;
    margin-right: 4px;
    vertical-align: -5px;
  }

  .lang-select {
    top: 5px;
    right: 6px;
    padding: 3px 7px;
    font-size: 0.7rem;
    border-radius: 8px;
  }

  main {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 6px;
  }

  .panel {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
    padding: 8px;
    gap: 6px;
    border-radius: 16px;
  }

  .toolbar {
    flex: none;
    margin-bottom: 0;
    gap: 6px;
  }

  .toolbar button {
    padding: 5px 10px;
    font-size: 0.76rem;
    border-radius: 10px;
  }

  .game-area {
    flex: 1;
    min-height: 0;
    flex-direction: row;
    align-items: stretch;
    gap: 8px;
  }

  .board-wrap {
    width: auto;
    min-width: 0;
    flex: 1 1 auto;
    display: flex;
    align-items: center;
    justify-content: center;
  }

  .board {
    width: min(56vw, calc((100dvh - 210px) / 2), calc((100vh - 210px) / 2), 340px);
    max-height: 100%;
    border-radius: 8px;
  }

  .overlay-box {
    padding: 14px 16px;
    margin: 8px;
  }

  .overlay-box h2 { font-size: 1.1rem; margin-bottom: 4px; }
  .overlay-box p { font-size: 0.78rem; margin-bottom: 10px; }
  .overlay-box button { padding: 8px 18px; font-size: 0.85rem; }

  .side {
    width: 116px;
    flex: none;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
  }

  .stat-block {
    padding: 4px 8px;
    border-radius: 10px;
    gap: 2px;
  }

  .stat-label { font-size: 0.64rem; }
  .stat-block b { font-size: 0.95rem; }

  .stat-row { gap: 6px; }
  .stat-row > div { padding: 4px 6px; border-radius: 10px; }
  .stat-row b { font-size: 0.88rem; }

  .combo {
    font-size: 0.72rem;
    padding: 3px 8px;
    border-radius: 999px;
  }

  .preview { padding: 6px 8px; border-radius: 10px; }
  .preview .stat-label { margin-bottom: 4px; }

  .mini-grid { width: 52px; gap: 1px; }
  .mini { width: 28px; gap: 1px; }

  .next-grid { gap: 4px; }

  .touch-controls {
    flex: none;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 5px;
    margin-top: 0;
  }

  .touch-controls button {
    min-height: 48px;
    font-size: 0.72rem;
    padding: 4px 2px;
    border-radius: 10px;
  }

  .touch-controls button small {
    font-size: 0.58rem;
  }

  .help { display: none; }
}

/* 高さが低いスマホ(横持ちなど)はさらに圧縮 */
@media (max-height: 500px) {
  .site-header { padding: 22px 8px 1px; }
  .site-header h1 { font-size: 0.85rem; }
  .logo { width: 18px; height: 18px; }
  .lang-select { top: 4px; right: 5px; padding: 2px 6px; font-size: 0.65rem; }
  .panel { gap: 4px; padding: 6px; }
  .toolbar button { padding: 4px 8px; font-size: 0.72rem; }
  .board { width: min(44vw, calc((100dvh - 150px) / 2), 300px); }
  .side { width: 104px; gap: 4px; }
  .stat-block { padding: 3px 6px; }
  .stat-block b { font-size: 0.88rem; }
  .touch-controls button { min-height: 40px; font-size: 0.66rem; }
  .mini-grid { width: 40px; }
  .next-grid { flex-wrap: nowrap; }
  .opp-grid { transform: scale(0.5); transform-origin: top center; }
  .combo { display: none; }
}

/* VS 相手盤面（右サイド） */
.vs-opp-block { text-align: center; }
.opp-grid { display: grid; grid-template-columns: repeat(10, 10px); grid-auto-rows: 10px; gap: 1px; background: #151226; padding: 4px; border-radius: 8px; margin: 4px auto 0; width: fit-content; }
.opp-cell { background: #241f3d; }
.opp-cell.filled { border-radius: 1px; }
.opp-cell.filled.p-G, .cell.filled.p-G { background: #9aa0a6; }
.opp-status { margin-top: 4px; font-size: .75rem; color: #cfc5f2; }

/* モード選択 */
.mode-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; flex-wrap: wrap; }
.mode-btn, .diff-btn { padding: 9px 12px; border-radius: 10px; border: 1.5px solid #5b4b8a; background: #211c3a; color: #fff; font-weight: 700; cursor: pointer; font-size: .9rem; }
.mode-btn.active, .diff-btn.active { background: #7c5cff; border-color: #7c5cff; }
.diff-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 10px; flex-wrap: wrap; }
/* スマホ: 対戦情報がはみ出さないように */
@media (max-width: 620px) {
  .side { max-height: 100%; overflow-y: auto; }
  .opp-grid { transform: scale(0.7); transform-origin: top center; }
  .vs-opp-block { order: 99; }
}

/* 相手盤面のピース色（.opp-cell の背景より優先させる） */
.opp-cell.filled.p-I { background: var(--c-I); }
.opp-cell.filled.p-O { background: var(--c-O); }
.opp-cell.filled.p-T { background: var(--c-T); }
.opp-cell.filled.p-S { background: var(--c-S); }
.opp-cell.filled.p-Z { background: var(--c-Z); }
.opp-cell.filled.p-J { background: var(--c-J); }
.opp-cell.filled.p-L { background: var(--c-L); }
.opp-cell.filled.p-G { background: #9aa0a6; }

/* 鑑賞モード: AI配置列のハイライト */
.board .cell.watch-target { background: rgba(255, 213, 79, 0.14); box-shadow: inset 0 0 0 1px rgba(255, 213, 79, 0.28); }
