/* マーラータン会計チャレンジ */
:root {
  --red: #b3122b;
  --red-dark: #8a0d20;
  --orange: #e8571f;
  --bg: #fff8ef;
  --card: #ffffff;
  --text: #3a1d12;
  --muted: #8a6f63;
  --line: #f0dccb;
  --yellow: #ffe7a3;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: #f3e3d3;
  color: var(--text);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic", "Meiryo", sans-serif;
  -webkit-text-size-adjust: 100%;
}
button { font-family: inherit; }
#app {
  max-width: 480px; margin: 0 auto; min-height: 100dvh;
  background: var(--bg); position: relative;
}
.screen { display: none; min-height: 100dvh; flex-direction: column; }
.screen.active { display: flex; }
.hidden { display: none !important; }
.small { font-size: 12px; color: var(--muted); line-height: 1.6; }
.center { text-align: center; }
h2 { font-size: 16px; margin: 20px 0 10px; }

/* ボタン */
.btn {
  border: none; border-radius: 14px; min-height: 48px; padding: 0 18px;
  font-size: 16px; font-weight: 800; cursor: pointer;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .4; }
.btn.primary { background: var(--red); color: #fff; }
.btn.secondary { background: var(--yellow); color: var(--text); }
.btn.ghost-btn { background: transparent; color: var(--muted); border: 2px solid var(--line); }
.btn.x { background: #111; color: #fff; }
.btn.big { min-height: 60px; font-size: 18px; width: 100%; }
.btn.wide { width: 100%; }

/* スタート */
#screen-start { padding: 24px 20px 32px; background: linear-gradient(180deg, var(--red) 0%, var(--orange) 55%, var(--bg) 55%); }
.start-hero { text-align: center; color: #fff; padding-top: 12px; }
.start-bowl { font-size: 88px; line-height: 1; animation: bob 2.4s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(-6px) rotate(-4deg); } }
.start-hero h1 { font-size: 28px; margin: 12px 0 8px; line-height: 1.3; }
.lead { font-size: 15px; line-height: 1.7; margin: 0; opacity: .95; }
.start-buttons { margin-top: 40px; display: flex; flex-direction: column; gap: 12px;
  background: var(--card); padding: 18px; border-radius: 20px; box-shadow: 0 8px 24px rgba(0,0,0,.12); }
.mode-note { font-size: 12px; color: var(--muted); margin: 0; line-height: 1.6; }
.best { margin-top: 18px; font-size: 14px; line-height: 1.8; text-align: center; }
.disclaimer { margin-top: auto; padding-top: 24px; font-size: 11px; color: var(--muted); line-height: 1.6; }

/* 上のバー */
.bar {
  display: flex; align-items: center; justify-content: space-between;
  background: var(--red); color: #fff; padding: 8px 8px; position: sticky; top: 0; z-index: 5;
}
.bar-title { font-weight: 800; font-size: 16px; display: flex; align-items: center; gap: 8px; }
.chip { background: var(--yellow); color: var(--text); font-size: 12px; padding: 3px 10px; border-radius: 999px; }
.chip:empty { display: none; }
.icon-btn { width: 44px; height: 44px; border: none; background: transparent; color: #fff; font-size: 26px; cursor: pointer; display: inline-block; }

/* ボウルのプレビュー */
.bowl-preview {
  margin: 12px 16px 4px; min-height: 76px; border-radius: 999px;
  background: radial-gradient(circle at 50% 40%, #d9482a, #a92a14);
  border: 6px solid #fff6e6; box-shadow: 0 4px 10px rgba(0,0,0,.12);
  display: flex; flex-wrap: wrap; align-content: center; justify-content: center;
  padding: 8px 20px; gap: 0 2px; font-size: 22px; line-height: 1.25;
}
.bowl-preview .empty { color: rgba(255,255,255,.8); font-size: 14px; font-weight: 700; }
.bowl-preview .pop { animation: pop .25s ease-out; }
@keyframes pop { from { transform: scale(1.8); } }

/* カテゴリのタブ */
.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 10px 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tab {
  flex: 0 0 auto; border: 2px solid var(--line); background: var(--card); color: var(--text);
  border-radius: 999px; padding: 0 14px; min-height: 40px; font-weight: 800; font-size: 14px; cursor: pointer;
}
.tab.active { background: var(--text); border-color: var(--text); color: #fff; }

/* 具材 */
.item-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; padding: 4px 16px 130px; }
.item {
  position: relative; background: var(--card); border: 2px solid var(--line); border-radius: 16px;
  padding: 10px 4px 8px; text-align: center; cursor: pointer; user-select: none; min-height: 112px;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
}
.item:active { transform: scale(.96); }
.item.on { border-color: var(--red); background: #fff0ec; }
.item .em { font-size: 34px; line-height: 1.2; }
.item .nm { font-size: 13px; font-weight: 800; }
.item .g { font-size: 11px; color: var(--muted); }
.item .badge {
  position: absolute; top: -6px; right: -6px; background: var(--red); color: #fff;
  min-width: 26px; height: 26px; border-radius: 13px; font-size: 14px; font-weight: 900;
  display: flex; align-items: center; justify-content: center; padding: 0 6px;
}
.item .minus {
  position: absolute; top: -6px; left: -6px; width: 30px; height: 30px; border-radius: 15px;
  border: none; background: var(--text); color: #fff; font-size: 18px; font-weight: 900; line-height: 1; cursor: pointer;
}

/* 下の固定バー */
.bottom {
  position: fixed; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 100%; max-width: 480px; background: rgba(255,248,239,.97);
  border-top: 2px solid var(--line); padding: 10px 16px calc(10px + env(safe-area-inset-bottom));
  display: flex; align-items: center; gap: 10px; z-index: 6;
}
.bottom-info { flex: 1; font-size: 14px; font-weight: 800; min-width: 0; }
.peek { display: flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 600; margin-top: 2px; }
.peek-value { font-size: 13px; color: var(--red); }
.peek-value:empty { display: none; }

/* スープ */
.panel { padding: 4px 20px 120px; }
.soup-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.soup {
  border: 2px solid var(--line); background: var(--card); border-radius: 16px; padding: 12px 4px;
  font-size: 13px; font-weight: 800; cursor: pointer; min-height: 88px;
}
.soup .em { display: block; font-size: 32px; margin-bottom: 4px; }
.soup.on { border-color: var(--red); background: #fff0ec; }
.lv { font-size: 18px; letter-spacing: 1px; }
.level-list { display: flex; flex-direction: column; gap: 8px; }
.level {
  display: flex; align-items: center; gap: 12px; text-align: left; width: 100%;
  border: 2px solid var(--line); background: var(--card); border-radius: 14px; padding: 10px 14px;
  min-height: 56px; cursor: pointer; color: var(--text);
}
.level.on { border-color: var(--red); background: #fff0ec; }
.level .pep { font-size: 20px; min-width: 76px; }
.level .lv-name { font-weight: 900; font-size: 16px; display: block; }
.level .lv-desc { font-size: 12px; color: var(--muted); }
input[type=range] { width: 100%; height: 36px; accent-color: var(--red); }

/* 計量アニメーション */
.weighing { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  background: linear-gradient(180deg, var(--red), var(--orange)); color: #fff; }
.scale { font-size: 96px; animation: wobble .4s ease-in-out infinite; }
@keyframes wobble { 50% { transform: rotate(-6deg); } }
.weigh-label { font-size: 18px; font-weight: 800; opacity: .9; }
.weigh-num { font-size: 56px; font-weight: 900; font-variant-numeric: tabular-nums; }

/* 結果 */
.result { padding: 16px 16px 40px; }
.share-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 12px; }
.card-img { width: 100%; border-radius: 16px; box-shadow: 0 8px 24px rgba(0,0,0,.18); display: block; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 14px; }
.receipt { list-style: none; padding: 0; margin: 0; background: var(--card); border-radius: 14px; border: 2px dashed var(--line); }
.receipt li { display: flex; justify-content: space-between; padding: 10px 14px; font-size: 14px; border-bottom: 1px dashed var(--line); }
.receipt li:last-child { border-bottom: none; font-weight: 900; font-size: 16px; }
.receipt .r-g { color: var(--muted); font-size: 12px; margin-left: 6px; }

/* プレイ画面（3D） */
.screen.play { position: relative; height: 100dvh; overflow: hidden; background: #ffd7ad; touch-action: manipulation; user-select: none; -webkit-user-select: none; }
.stage { position: absolute; inset: 0; }
.stage canvas { display: block; touch-action: none; }
.hud-top {
  position: absolute; top: 0; left: 0; right: 0; padding: calc(10px + env(safe-area-inset-top)) 14px 0;
  display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none;
}
.hud-left { display: flex; flex-direction: column; gap: 6px; }
.hud-pill { background: rgba(40,20,12,.82); color: #fff; font-weight: 800; font-size: 14px; padding: 6px 12px; border-radius: 999px; }
.hud-pill.gold { background: #f5c518; color: var(--text); }
.hud-pill:empty { display: none; }
.timer {
  min-width: 72px; height: 72px; border-radius: 36px; background: #fff; color: var(--red);
  font-size: 34px; font-weight: 900; display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(0,0,0,.2); font-variant-numeric: tabular-nums; border: 4px solid var(--red);
}
.timer.hurry { background: var(--red); color: #fff; animation: pulse .5s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.1); } }
.gauge-wrap { position: absolute; left: 14px; right: 14px; bottom: calc(14px + env(safe-area-inset-bottom)); display: flex; align-items: center; gap: 8px; pointer-events: none; }
.stop-btn { pointer-events: auto; min-height: 48px; padding: 0 16px; box-shadow: 0 4px 12px rgba(0,0,0,.25); white-space: nowrap; }
.stop-btn:disabled { opacity: .5; }
.gauge-label { font-size: 12px; font-weight: 900; color: var(--text); background: rgba(255,255,255,.85); padding: 3px 8px; border-radius: 8px; }
.gauge { flex: 1; height: 14px; background: rgba(255,255,255,.7); border-radius: 7px; overflow: hidden; border: 2px solid rgba(58,29,18,.5); }
.gauge-fill { height: 100%; width: 0; background: linear-gradient(90deg, #66bb6a, #ffca28 60%, #e53935 90%); transition: width .2s; }
.countdown {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  font-size: 120px; font-weight: 900; color: #fff; text-shadow: 0 6px 0 var(--red), 0 10px 24px rgba(0,0,0,.35);
  pointer-events: none;
}
.countdown:empty { display: none; }
.countdown.big-text { font-size: 64px; text-align: center; line-height: 1.2; }
.countdown .go { animation: zoom .5s ease-out; display: inline-block; }
@keyframes zoom { from { transform: scale(2.2); opacity: 0; } }
.hud-msg {
  position: absolute; left: 50%; bottom: calc(76px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(255,255,255,.9); color: var(--text); font-weight: 800; font-size: 14px;
  padding: 6px 14px; border-radius: 999px; white-space: nowrap; pointer-events: none; transition: opacity .3s;
}
.pop {
  position: fixed; pointer-events: none; font-weight: 900; font-size: 18px; color: #fff;
  text-shadow: 0 2px 0 var(--red), 0 0 6px rgba(0,0,0,.4); transform: translate(-50%, -50%);
  animation: rise .8s ease-out forwards; white-space: nowrap; z-index: 8;
}
.pop.jumbo { color: #ffe066; font-size: 22px; }
@keyframes rise { to { transform: translate(-50%, -150%); opacity: 0; } }

/* アプリ内ブラウザの案内・3Dが動かないとき */
.inapp-hint { margin-top: 14px; background: #fff3cd; border: 2px solid #f5c518; border-radius: 12px; padding: 10px 12px; font-size: 13px; line-height: 1.6; }
.gl-error { position: absolute; inset: 0; background: rgba(40,20,12,.75); display: flex; align-items: center; justify-content: center; padding: 20px; z-index: 30; }
.gl-box { background: var(--card); border-radius: 18px; padding: 20px; text-align: center; display: flex; flex-direction: column; gap: 10px; max-width: 360px; }
.gl-icon { font-size: 48px; }
.gl-box p { margin: 0; line-height: 1.6; }

/* トースト */
.toast {
  position: fixed; left: 50%; bottom: 100px; transform: translateX(-50%) translateY(20px);
  background: rgba(40,20,12,.92); color: #fff; padding: 10px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 700; opacity: 0; pointer-events: none; transition: .25s; z-index: 20; max-width: 90%;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
