:root {
  --bg: #f4f5fb;
  --card: #ffffff;
  --ink: #1f2333;
  --sub: #6b7080;
  --line: #e3e5ef;
  --brand: #5b6cff;
  --brand-ink: #ffffff;
  --hit: #ff5b8a;
  --shadow: 0 6px 24px rgba(40, 44, 80, .08);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
/* hidden属性を最優先（display:flex等の指定に負けないように） */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-text-size-adjust: 100%;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: env(safe-area-inset-top) 16px 0;
  height: calc(54px + env(safe-area-inset-top));
  background: rgba(244, 245, 251, .85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 800; font-size: 19px; letter-spacing: .02em; }
.top-actions { display: flex; align-items: center; gap: 2px; }

.lead {
  font-size: 14px; line-height: 1.6; color: var(--sub);
  margin: 2px 4px 14px;
}
.link-btn {
  border: none; background: none; color: var(--brand);
  font-weight: 700; font-size: 14px; cursor: pointer; padding: 0; text-decoration: underline;
}

#main { max-width: 720px; margin: 0 auto; padding: 16px; }
.view { animation: fade .2s ease; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

.card {
  background: var(--card);
  border-radius: 18px;
  padding: 18px;
  box-shadow: var(--shadow);
}

.field { margin-bottom: 22px; }
.field > label, .row-head label { font-weight: 700; font-size: 15px; display: block; }
.row-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.hint { color: var(--sub); font-size: 13px; font-weight: 500; }

/* stepper */
.stepper { display: flex; align-items: center; gap: 14px; margin-top: 10px; }
.step {
  width: 44px; height: 44px; border-radius: 12px;
  border: none; background: var(--brand); color: #fff;
  font-size: 24px; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.step:active { transform: scale(.94); }
#countLabel { font-size: 26px; font-weight: 800; min-width: 40px; text-align: center; }

/* input grids */
.inputs-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}
.inputs-grid input {
  width: 100%;
  border: 1.5px solid var(--line);
  border-radius: 11px;
  padding: 11px 12px;
  font-size: 15px;
  background: #fafbff;
  color: var(--ink);
}
.inputs-grid input:focus { outline: none; border-color: var(--brand); background: #fff; }

.check {
  display: flex; align-items: center; gap: 9px;
  font-size: 14px; font-weight: 600; color: var(--ink);
  margin: 4px 2px 18px; cursor: pointer; user-select: none;
}
.check input { width: 19px; height: 19px; accent-color: var(--brand); }

.add-bar {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: #eef0ff; border: 1px solid #d9ddff; color: #3a3f66;
  font-size: 13px; font-weight: 600;
  border-radius: 12px; padding: 9px 12px; margin: 0 0 12px;
}
.add-bar b { color: var(--brand); font-size: 15px; }
.add-bar .mini-btn { margin-left: auto; }

.primary {
  width: 100%;
  border: none;
  border-radius: 14px;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: 17px;
  font-weight: 800;
  padding: 15px;
  cursor: pointer;
}
.primary:active { transform: scale(.99); }

.ghost-btn {
  border: none; background: transparent; color: var(--brand);
  font-size: 15px; font-weight: 700; cursor: pointer; padding: 8px 6px;
}
.ghost-btn.danger { color: #d23b5b; }
.mini-btn {
  border: 1.5px solid var(--brand); background: #fff; color: var(--brand);
  font-size: 13px; font-weight: 700; border-radius: 999px; padding: 6px 13px; cursor: pointer;
}

/* ladder view */
.toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 6px; }
.toolbar-actions { display: flex; gap: 4px; }
.guide { color: var(--sub); font-size: 13px; text-align: center; margin: 4px 0 12px; }

.ladder-wrap {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 10px 4px;
}
.ladder-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }
#ladder { display: block; margin: 0 auto; }

.cap {
  cursor: pointer;
  transition: transform .1s;
}
.cap:active { transform: scale(.96); }

/* たどる線とゴールの演出 */
.trace { filter: drop-shadow(0 0 5px rgba(255, 91, 138, .5)); }
.token { filter: drop-shadow(0 0 7px rgba(255, 255, 255, .9)); }
@keyframes pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.35); }
  100% { transform: scale(1); }
}
.goal.pop { animation: pop .55s cubic-bezier(.2,1.4,.5,1); transform-box: fill-box; transform-origin: center; }
@keyframes winGlow {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.18); }
}
.cap.win { animation: winGlow .6s ease 2; transform-box: fill-box; transform-origin: center; }

/* 結果リストの登場アニメ */
@keyframes slideUp { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.result-list li { animation: slideUp .3s ease both; }

/* 紙吹雪キャンバス */
#confetti {
  position: fixed; inset: 0; width: 100%; height: 100%;
  pointer-events: none; z-index: 9999;
}

/* あたりバナー */
.win-banner {
  position: fixed; left: 50%; top: 28%; transform: translate(-50%, -50%) scale(.7);
  background: linear-gradient(135deg, #ff5b8a, #ff8f5b);
  color: #fff; font-weight: 800; font-size: 22px;
  padding: 16px 28px; border-radius: 16px;
  box-shadow: 0 10px 40px rgba(255, 91, 138, .4);
  z-index: 10000; pointer-events: none; opacity: 0;
  transition: transform .4s cubic-bezier(.2,1.5,.4,1), opacity .3s ease;
  white-space: nowrap;
}
.win-banner.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }

/* result */
.result-area {
  margin-top: 16px;
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 14px 16px;
}
.result-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; margin-bottom: 8px; }
.result-list { list-style: none; margin: 0; padding: 0; }
.result-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 0; border-bottom: 1px solid var(--line);
  font-size: 15px;
}
.result-list li:last-child { border-bottom: none; }
.result-list .nm { font-weight: 700; }
.result-list .arrow { color: var(--sub); }
.result-list .gl { color: var(--brand); font-weight: 700; }
.result-list .badge {
  margin-left: auto; font-size: 11px; font-weight: 800; color: #fff;
  background: var(--hit); border-radius: 999px; padding: 2px 9px;
}
.result-list li.tappable { cursor: pointer; border-radius: 8px; padding: 9px 8px; transition: background .12s; }
.result-list li.tappable:hover { background: #f4f5fb; }
.result-list li.tappable:active { background: #eef0ff; }

/* history */
.history-list { display: flex; flex-direction: column; gap: 12px; margin-top: 8px; }
.hist-card {
  background: var(--card); border-radius: 16px; box-shadow: var(--shadow); padding: 14px 16px;
}
.hist-card .when { color: var(--sub); font-size: 12px; margin-bottom: 8px; display: flex; justify-content: space-between; }
.hist-card .del { color: #d23b5b; cursor: pointer; font-size: 12px; font-weight: 700; }
.hist-card ul { list-style: none; margin: 0; padding: 0; }
.hist-card li { display: flex; gap: 8px; padding: 5px 0; font-size: 14px; }
.hist-card .nm { font-weight: 700; min-width: 0; }
.hist-card .gl { color: var(--brand); font-weight: 700; }

/* 使い方モーダル */
.overlay {
  position: fixed; inset: 0; z-index: 10001;
  background: rgba(20, 24, 45, .45);
  display: flex; align-items: flex-end; justify-content: center;
  padding: 0; animation: fade .2s ease;
}
.help-sheet {
  background: var(--card); width: 100%; max-width: 560px;
  border-radius: 20px 20px 0 0; padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  max-height: 88vh; overflow-y: auto;
  animation: sheetUp .25s cubic-bezier(.2,.9,.3,1);
}
@keyframes sheetUp { from { transform: translateY(40px); opacity: .6; } to { transform: none; opacity: 1; } }
.help-sheet h2 { margin: 0 0 14px; font-size: 19px; }
.help-steps { margin: 0 0 18px; padding-left: 22px; }
.help-steps li { margin-bottom: 12px; font-size: 14.5px; line-height: 1.6; color: var(--ink); }
.help-steps b { font-weight: 700; }

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  20%, 60% { transform: translateX(-6px); }
  40%, 80% { transform: translateX(6px); }
}
.add-bar.shake { animation: shake .35s ease; }

.empty { text-align: center; padding: 60px 20px; color: var(--sub); }
.empty-title { font-weight: 700; color: var(--ink); margin-bottom: 6px; }
.empty-sub { font-size: 14px; }
