/* 最小版のスタイル。カードは画像を使わず CSS で描く（演出・画像は後で差し替える） */

:root {
  --felt: #0b3d2e;
  --felt-light: #145c45;
  --slot: rgba(255, 255, 255, 0.12);
  --card-face: #fdfcf7;
  --card-edge: rgba(0, 0, 0, 0.25);
  --red: #c8102e;
  --black: #1a1a1a;
  --hint: #ffd84d;
  --move-ms: 220ms;
  /* カードの寸法は ui.js がレイアウト時に設定する */
  --cw: 48px;
  --ch: 67px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  display: flex;
  flex-direction: column;
  background: radial-gradient(ellipse at 50% 30%, var(--felt-light), var(--felt) 70%);
  background-color: var(--felt);
  color: #fff;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  /* ダブルタップでの拡大を防ぐ */
  touch-action: manipulation;
}

/* ---------- 上部の情報 ---------- */

#status {
  display: flex;
  align-items: center;
  gap: 16px;
  /* 下に余白を取り、歯車ボタンと山札を離して誤タップを防ぐ */
  padding: calc(env(safe-area-inset-top) + 2px) calc(env(safe-area-inset-right) + 4px) 8px
    calc(env(safe-area-inset-left) + 14px);
  font-size: 17px;
  font-weight: 600;
}

#status span {
  opacity: 0.9;
}

/* 押しやすい大きさにし、手数などの表示と区別できるよう、ツールバーと同じ背景に枠線を付けてボタンらしく見せる */
#settings-btn {
  margin-left: auto;
  width: 46px;
  height: 46px;
  padding: 0;
  border: 1.5px solid rgba(255, 255, 255, 0.45);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.15);
  font-size: 28px;
  line-height: 1;
}

#settings-btn:active {
  background: rgba(255, 255, 255, 0.3);
}

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

#board {
  position: relative;
  flex: 1;
  margin: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left);
  overflow: hidden;
  /* スクロールやズームのジェスチャーにタップを奪われないようにする */
  touch-action: none;
  /* カードの z-index（移動中は 1000 以上）を盤面の中だけで比べ、設定画面などの上に出ないようにする */
  isolation: isolate;
  z-index: 0;
}

.slot {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw);
  height: var(--ch);
  border-radius: calc(var(--cw) * 0.1);
  background: var(--slot);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: calc(var(--cw) * 0.5);
  color: rgba(255, 255, 255, 0.35);
}

.card {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--cw);
  height: var(--ch);
  perspective: 600px;
  transition: transform var(--move-ms) ease-out;
  will-change: transform;
}

.no-anim .card,
.no-anim .card-inner {
  transition: none !important;
}

.card-inner {
  position: relative;
  width: 100%;
  height: 100%;
  transform-style: preserve-3d;
  transition: transform var(--move-ms) ease-out;
}

.card.down .card-inner {
  transform: rotateY(180deg);
}

.face,
.back {
  position: absolute;
  inset: 0;
  border-radius: calc(var(--cw) * 0.1);
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  box-shadow: 0 1px 2px var(--card-edge);
}

.face {
  background: var(--card-face);
  border: 1px solid rgba(0, 0, 0, 0.15);
  color: var(--black);
}

.card.red .face {
  color: var(--red);
}

.face .corner {
  position: absolute;
  left: calc(var(--cw) * 0.07);
  top: calc(var(--cw) * 0.03);
  font-size: calc(var(--cw) * 0.34);
  font-weight: 700;
  line-height: 1;
  letter-spacing: -0.06em;
  display: flex;
  align-items: baseline;
  gap: 1px;
}

.face .corner .s {
  font-size: calc(var(--cw) * 0.3);
}

.face .pip {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(var(--ch) * 0.08);
  text-align: center;
  font-size: calc(var(--cw) * 0.62);
  line-height: 1;
}

.back {
  transform: rotateY(180deg);
  background:
    repeating-linear-gradient(45deg, rgba(255, 255, 255, 0.12) 0 2px, transparent 2px 6px),
    repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.12) 0 2px, transparent 2px 6px),
    #1d4f9c;
  border: calc(var(--cw) * 0.06) solid #fff;
}

/* ドラッグ中のカードは指に追従させ（アニメーションなし）、浮いて見えるよう影を大きくする */
.card.dragging {
  transition: none;
}

.card.dragging .face {
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.45);
}

/* 動かせないカードをタップしたとき */
.card.shake {
  animation: shake 0.3s;
}

@keyframes shake {
  25% { translate: -4px 0; }
  50% { translate: 4px 0; }
  75% { translate: -2px 0; }
}

/* ヒントで示すカード・置き場所 */
.card.hint .face,
.slot.hint {
  box-shadow: 0 0 0 3px var(--hint), 0 0 12px var(--hint);
}

/* ---------- 下部のボタン ---------- */

#toolbar {
  display: flex;
  gap: 6px;
  padding: 6px calc(env(safe-area-inset-right) + 8px) calc(env(safe-area-inset-bottom) + 8px)
    calc(env(safe-area-inset-left) + 8px);
}

#toolbar button {
  flex: 1;
}

button {
  font: inherit;
  font-size: 14px;
  padding: 10px 4px;
  border: none;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.15);
  color: #fff;
  /* touch-action は継承されないので、ボタンにも直接指定する */
  touch-action: manipulation;
}

button:active {
  background: rgba(255, 255, 255, 0.3);
}

button:disabled {
  opacity: 0.4;
}

[hidden] {
  display: none !important;
}

/* ---------- メッセージ・クリア画面 ---------- */

#message {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 70px);
  transform: translateX(-50%);
  padding: 8px 16px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.75);
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
  z-index: 20;
  transform: translateX(-50%) translateZ(0);
}

/* クリア画面・設定画面・確認ダイアログ共通の、盤面に重ねる画面 */
.overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.45);
  z-index: 10;
  /* Safari は 3D 変形（カードの裏返し）した要素を z-index に関係なく手前に描くことがあるので、こちらも合成レイヤーにして手前へ出す */
  transform: translateZ(0);
}

.overlay .panel {
  width: min(340px, 100%);
  padding: 24px;
  border-radius: 16px;
  background: var(--felt);
  text-align: center;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
}

.overlay .buttons {
  display: flex;
  gap: 8px;
  margin-top: 20px;
}

.overlay .buttons button {
  flex: 1;
}

button.primary {
  background: rgba(255, 255, 255, 0.85);
  color: var(--felt);
  font-weight: 700;
}

button.primary:active {
  background: #fff;
}

button.danger {
  background: #e0566b;
  color: #fff;
}

#win h1 {
  margin: 0 0 8px;
  font-size: 28px;
}

#win button {
  margin: 12px 4px 0;
  padding: 10px 24px;
}

/* ---------- 設定画面 ---------- */

#settings .panel {
  text-align: left;
}

#settings h1 {
  margin: 0 0 16px;
  font-size: 20px;
  text-align: center;
}

#settings section + section {
  margin-top: 18px;
}

#settings h2 {
  margin: 0 0 8px;
  font-size: 14px;
  font-weight: 600;
  opacity: 0.85;
}

/* 選択肢を横に並べたボタン（どれか 1 つを選ぶ） */
.segmented {
  display: flex;
  gap: 4px;
  padding: 3px;
  border-radius: 12px;
  background: rgba(0, 0, 0, 0.25);
}

.segmented button {
  flex: 1;
  background: none;
}

.segmented button.selected {
  background: rgba(255, 255, 255, 0.85);
  color: var(--felt);
  font-weight: 700;
}

.overlay .note {
  margin: 8px 0 0;
  font-size: 12px;
  line-height: 1.5;
  opacity: 0.7;
}

#settings > .panel > .note {
  margin-top: 18px;
}

#dialog-text {
  margin: 0;
  font-size: 15px;
  line-height: 1.6;
  white-space: pre-line;
}
