*,
*::before,
*::after { box-sizing: border-box; }

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

body {
  font-family: 'M PLUS Rounded 1c', 'Hiragino Maru Gothic ProN', sans-serif;
  font-weight: 800;
  color: #6b4426;
  background-color: #f5c59a;
  background-image:
    linear-gradient(45deg, rgba(255, 255, 255, .13) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, .13) 75%),
    linear-gradient(45deg, rgba(255, 255, 255, .13) 25%, transparent 25%, transparent 75%, rgba(255, 255, 255, .13) 75%);
  background-size: 72px 72px;
  background-position: 0 0, 36px 36px;
  overflow: hidden;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

button { font: inherit; cursor: pointer; }

.app {
  max-width: 480px;
  height: 100dvh;
  margin: 0 auto;
  padding: max(10px, env(safe-area-inset-top)) 16px max(14px, env(safe-area-inset-bottom));
  display: flex;
  flex-direction: column;
  gap: 10px;
}

/* ---------- ヘッダー ---------- */
.top { display: flex; align-items: center; gap: 8px; }

.top__logo {
  margin: 0 auto 0 0;
  font-size: 20px;
  white-space: nowrap;
  letter-spacing: .02em;
  color: #fff;
  text-shadow: 0 2px 0 #c0612a, 0 -1px 0 #c0612a, 2px 0 0 #c0612a, -2px 0 0 #c0612a;
  transform: rotate(-3deg);
}
.top__logo span { color: #ffe27a; }

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

.meta__level {
  font-size: 12px;
  white-space: nowrap;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .6);
}

.top__btn {
  height: 34px;
  min-width: 34px;
  padding: 0 10px;
  white-space: nowrap;
  border: 0;
  border-radius: 10px;
  color: #fff;
  background: #9a8778;
  box-shadow: 0 3px 0 #6f5f53;
}
.top__btn:active { transform: translateY(2px); box-shadow: 0 1px 0 #6f5f53; }
.top__btn--sound[aria-pressed="false"] { opacity: .55; text-decoration: line-through; }
.top__btn--speed[aria-pressed="true"] { background: #ff8a3d; box-shadow: 0 3px 0 #c75d1c; }

.progress {
  flex: 1;
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .45);
  overflow: hidden;
}
.progress span {
  display: block;
  height: 100%;
  width: 0;
  background: #ff8a3d;
  transition: width .2s;
}

/* ---------- 盤面 ---------- */
.stage-wrap { position: relative; flex: 1 1 auto; min-height: 180px; }
.stage-wrap canvas { position: absolute; inset: 0; }

/* ---------- タイル ---------- */
.tile,
.slot {
  display: grid;
  place-items: center;
  border: 0;
  border-radius: 12px;
  color: var(--t);
  background: var(--c);
  box-shadow: 0 5px 0 var(--d), 0 8px 10px rgba(110, 55, 20, .22);
  text-shadow: 0 2px 0 rgba(0, 0, 0, .18);
  font-variant-numeric: tabular-nums;
}

.slots { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; }
.slot { height: min(58px, 7dvh); font-size: 22px; }
.slot--empty {
  background: rgba(255, 255, 255, .5);
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, .9);
}
.slot--locked {
  background: rgba(120, 80, 50, .18);
  box-shadow: inset 0 0 0 2px rgba(120, 80, 50, .12);
}
.slot--locked::before {
  content: '';
  width: 14px;
  height: 11px;
  border-radius: 3px;
  background: rgba(107, 68, 38, .35);
  box-shadow: 0 -7px 0 -2px transparent;
}
.slot--landing { visibility: hidden; }
.slots.is-shake { animation: shake .3s; }

.deck {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  padding: 4px 10px 0;
}
.deck__col { display: flex; flex-direction: column; gap: 9px; }
.tile { height: min(56px, 6.6dvh); font-size: 24px; }
.tile--front { outline: 3px solid #fff; outline-offset: -1px; }
.tile--front:active { transform: translateY(3px); box-shadow: 0 2px 0 var(--d); }
.tile--back { pointer-events: none; filter: saturate(.8) brightness(.93); transform: scale(.93); }
.tile--ghost { position: fixed; z-index: 10; margin: 0; pointer-events: none; }
.deck__more { text-align: center; font-size: 13px; color: rgba(107, 68, 38, .7); }

@keyframes shake {
  25% { transform: translateX(-6px); }
  50% { transform: translateX(6px); }
  75% { transform: translateX(-3px); }
}

/* ---------- 結果 ---------- */
.overlay {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(80, 40, 15, .35);
}
.overlay[hidden] { display: none; }
.overlay__card {
  width: min(320px, 100%);
  padding: 26px 20px 22px;
  border-radius: 20px;
  text-align: center;
  background: #fff8ef;
  box-shadow: 0 8px 0 #e7c9a0;
  animation: pop .3s cubic-bezier(.3, 1.5, .5, 1);
}
.overlay__title { margin: 0 0 6px; font-size: 26px; color: #d8622a; }
.overlay__msg { margin: 0 0 18px; font-size: 14px; font-weight: 700; }
.overlay__btn {
  padding: 12px 36px;
  border: 0;
  border-radius: 14px;
  font-size: 18px;
  color: #fff;
  background: #ff8a3d;
  box-shadow: 0 5px 0 #c75d1c;
}
.overlay__btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #c75d1c; }

@keyframes pop { from { transform: scale(.7); opacity: 0; } }
