:root {
  --copper: #b87333;
  --copper-dark: #8a5424;
  --gold: #f0c24b;
  --amber: #ffb84d;
  --panel: #241a12;
  --panel-edge: #3a2b1d;
  --reel-bg: #f7f2e4;
  --cell: 88px;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  background: radial-gradient(ellipse at 50% -10%, #2c2016 0%, #14100c 55%, #0b0806 100%);
  color: #e8dcc8;
  font-family: -apple-system, "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  overscroll-behavior: none;
  touch-action: manipulation; /* ダブルタップズーム抑止(スクロールは許可) */
}
body { padding-top: env(safe-area-inset-top); padding-bottom: env(safe-area-inset-bottom); }

#app { max-width: 440px; margin: 0 auto; padding: 8px 10px 24px; }

header { display: flex; align-items: center; justify-content: center; gap: 8px; padding: 4px 0 6px; position: relative; }
#menuBtn {
  position: absolute; right: 0; top: 0;
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid #4a3826;
  background: #2b2117; color: #cbb890; font-size: 20px; touch-action: manipulation;
}
header h1 {
  font-size: 22px; letter-spacing: 6px; font-weight: 800;
  background: linear-gradient(180deg, #ffe9a8, #f0c24b 45%, #a8741f 55%, #ffd97a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
}
.ver { font-size: 12px; color: #8d7c63; }

/* ---- データカウンター ---- */
#counterBar { display: flex; gap: 5px; margin-bottom: 8px; }
.chip {
  flex: 1; background: #191410; border: 1px solid #3a2f22; border-radius: 8px;
  text-align: center; padding: 4px 2px 5px; font-size: 10px; color: #9c8b71;
}
.chip b { display: block; font-size: 15px; color: #f3e9d5; font-variant-numeric: tabular-nums; margin-top: 1px; }
.chip b.gold { color: var(--gold); }
.chip b.cask { color: #d98f4e; }

/* ---- 筐体 ---- */
#machine {
  background: linear-gradient(180deg, #2c2118, var(--panel) 30%, #1c140e);
  border: 2px solid var(--copper-dark);
  border-radius: 18px;
  padding: 10px 12px 14px;
  box-shadow: 0 6px 24px rgba(0,0,0,.55), inset 0 1px 0 rgba(255,200,120,.15);
  cursor: pointer;
}
#machine.bonus {
  border-color: var(--gold);
  animation: machineGlow .8s ease-in-out infinite;
}
@keyframes machineGlow {
  0%, 100% { box-shadow: 0 0 16px 2px rgba(255,180,60,.5), 0 6px 24px rgba(0,0,0,.55); }
  50% { box-shadow: 0 0 36px 10px rgba(255,195,85,.95), 0 6px 24px rgba(0,0,0,.55); }
}
#machine.peka { animation: pekaFlash .16s steps(2) 5; }
@keyframes pekaFlash { 50% { filter: brightness(1.9) saturate(1.4); } }

/* ---- LEDライトバー ---- */
#lightBar {
  height: 10px; border-radius: 6px; margin: 0 2px 8px;
  background: repeating-linear-gradient(90deg, #4a3a26 0 6px, #241b12 6px 18px);
  border: 1px solid #3a2d1c;
}
#machine.bonus #lightBar {
  background: repeating-linear-gradient(90deg, #ffe9a8 0 6px, #c9541e 6px 12px, #ffb84d 12px 18px);
  background-size: 18px 100%;
  animation: ledChase .38s linear infinite;
  box-shadow: 0 0 14px rgba(255,190,80,.85);
  border-color: #d99b45;
}
@keyframes ledChase { to { background-position: 18px 0; } }

#reelFrame.winflash { animation: winFlash .45s ease-out; }
@keyframes winFlash { 30% { filter: brightness(1.55); } }

/* ---- 告知ランプ ---- */
#lampArea { position: relative; height: 92px; display: flex; align-items: center; justify-content: center; }
#lamp { width: 128px; height: 92px; transition: filter .15s; }
#lamp svg { width: 100%; height: 100%; }
#lamp .dome { transition: fill .12s; }
#lamp.lit { animation: lampGlow 1.1s ease-in-out infinite; }
#lamp.lit .dome { fill: rgba(255, 190, 80, .92); }
@keyframes lampGlow {
  0%, 100% { filter: drop-shadow(0 0 6px rgba(255,180,60,.9)) drop-shadow(0 0 22px rgba(255,150,30,.7)); }
  50% { filter: drop-shadow(0 0 14px rgba(255,200,90,1)) drop-shadow(0 0 40px rgba(255,160,40,.95)); }
}

#bonusBanner {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: 2px;
  background: rgba(20, 12, 4, .82); border-radius: 12px;
}
#bonusName {
  font-size: 26px; font-weight: 900; letter-spacing: 4px;
  background: linear-gradient(180deg, #fff3c4, var(--gold) 40%, #b0791d 60%, #ffe29a);
  -webkit-background-clip: text; background-clip: text; color: transparent;
  animation: bannerFlash .5s steps(2) infinite;
}
#bonusLeft { font-size: 13px; color: #ffd98a; font-variant-numeric: tabular-nums; }
@keyframes bannerFlash { 50% { opacity: .55; } }

/* ---- リール ---- */
#reelFrame {
  position: relative;
  background: linear-gradient(180deg, var(--copper-dark), var(--copper) 12%, #6f421c 88%, #4c2c11);
  border-radius: 12px; padding: 8px;
}
#reelWindow {
  display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 5px;
  background: #2a2118; border-radius: 8px; overflow: hidden;
  height: calc(var(--cell) * 3);
}
.reelCol { position: relative; overflow: hidden; background: var(--reel-bg); }
.reelCol::after {
  content: ""; position: absolute; inset: 0; pointer-events: none;
  background: linear-gradient(180deg, rgba(30,20,10,.42) 0%, rgba(30,20,10,0) 18%, rgba(30,20,10,0) 82%, rgba(30,20,10,.42) 100%);
}
.strip { will-change: transform; }
.cell { height: var(--cell); display: flex; align-items: center; justify-content: center; }
.cell svg { width: 88%; height: 88%; }

.lineMark { position: absolute; top: 50%; width: 0; height: 0; transform: translateY(-50%); }
.lineMark.left { left: 1px; border-top: 7px solid transparent; border-bottom: 7px solid transparent; border-left: 8px solid #ffe1a0; }
.lineMark.right { right: 1px; border-top: 7px solid transparent; border-bottom: 7px solid transparent; border-right: 8px solid #ffe1a0; }

/* ---- LED表示 ---- */
#ledRow { display: flex; gap: 8px; margin-top: 10px; align-items: stretch; }
.led {
  flex: 1; background: #0d0906; border: 1px solid #46351f; border-radius: 8px;
  padding: 4px 10px 6px; display: flex; align-items: baseline; justify-content: space-between;
}
.led label { font-size: 10px; color: #8d7455; letter-spacing: 1px; }
.led span {
  font-family: "Courier New", monospace; font-weight: 700; font-size: 22px;
  color: var(--amber); text-shadow: 0 0 8px rgba(255,160,50,.55);
  font-variant-numeric: tabular-nums; min-width: 2ch; text-align: right;
}
.replayLed {
  flex: 0 0 auto; display: flex; align-items: center; font-size: 11px; font-weight: 700;
  color: #7fd4ff; text-shadow: 0 0 8px rgba(90,190,255,.8); letter-spacing: 1px;
  animation: bannerFlash .6s steps(2) infinite;
}

/* ---- 操作系 ---- */
#controls { margin-top: 12px; }
#stopRow { display: flex; justify-content: space-around; gap: 10px; }
.stopBtn {
  width: 76px; height: 76px; border-radius: 50%; border: 3px solid #5c3a17;
  background: radial-gradient(circle at 35% 30%, #ff5b5b, #c62828 60%, #7d1414);
  color: #fff; font-size: 18px; font-weight: 900;
  box-shadow: 0 5px 0 #4c1010, 0 8px 14px rgba(0,0,0,.5);
  touch-action: manipulation;
}
.stopBtn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 #4c1010; }
.stopBtn:disabled { filter: grayscale(.75) brightness(.55); box-shadow: 0 5px 0 #241010; }
.stopBtn span { pointer-events: none; }

#tapHint {
  text-align: center; font-size: 12px; color: #8d7a5e; margin-top: 12px; letter-spacing: 1px;
}
.payNote { font-size: 10px; color: #7a684d; margin-top: 6px; text-align: center; }

/* ---- 配当表 ---- */
#paytable { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px 8px; margin-top: 12px; }
.payItem {
  display: flex; align-items: center; gap: 6px; font-size: 12px; color: #b3a184;
  background: #191410; border: 1px solid #2e2519; border-radius: 8px; padding: 3px 8px;
}
.payIcon { width: 34px; height: 26px; flex: 0 0 auto; background: #f7f2e4; border-radius: 4px; display: flex; align-items: center; justify-content: center; }
.payIcon svg { width: 90%; height: 90%; }

/* ---- トースト ---- */
#toast {
  position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%);
  background: rgba(15, 10, 5, .92); color: #ffe3ad; border: 1px solid #6d4d1e;
  padding: 10px 18px; border-radius: 10px; font-size: 14px; z-index: 50;
  max-width: 86vw; text-align: center;
}

/* ---- メニュー ---- */
#menuOverlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.62); z-index: 40;
  display: flex; align-items: flex-end; justify-content: center;
}
#menu {
  width: 100%; max-width: 440px; max-height: 82vh; overflow-y: auto;
  background: #1d1610; border: 1px solid #4a3826; border-radius: 18px 18px 0 0;
  padding: 18px 18px 26px;
}
#menu h2 { font-size: 17px; color: #f0e2c4; margin-bottom: 12px; }
#menu section { margin-bottom: 18px; }
#menu h3 { font-size: 13px; color: #a58e63; margin-bottom: 8px; }
#settingNow { color: var(--gold); }
#settingBtns, #forceBtns { display: flex; flex-wrap: wrap; gap: 6px; }
#settingBtns button, #forceBtns button, #addCredits, #resetData, #menuClose {
  font-size: 16px; padding: 9px 14px; border-radius: 10px;
  border: 1px solid #5a462c; background: #2b2117; color: #e8dcc8;
  touch-action: manipulation;
}
#settingBtns button.sel, #forceBtns button.sel { background: var(--copper); color: #fff; border-color: #e0a05c; }
.opt { display: flex; align-items: center; gap: 9px; font-size: 15px; padding: 7px 0; }
.opt input { width: 20px; height: 20px; accent-color: var(--copper); }
.note { font-size: 12px; color: #c9a15e; margin-top: 6px; min-height: 1em; }
#resetData.danger { border-color: #7d3030; color: #ff9d9d; }
#menuClose { width: 100%; margin-top: 4px; background: #3a2d1e; }

.hidden { display: none !important; }

@media (max-width: 430px) { :root { --cell: 21vw; } }
