:root {
  --bg: #eef2fb;
  --bg-elev: #ffffff;
  --bg-elev-2: #f3f6fc;
  --line: #e1e7f2;
  --text: #1f2533;
  --text-dim: #707888;
  --red: #e2231a;
  --red-dim: #c4170f;
  --green: #16a34a;
  --gold: #d98a00;
  --blue: #2f6fed;
  --tdl: #2f6fed;
  --tds: #0f9d96;
  --radius: 18px;
  --radius-sm: 12px;
  --tap: 48px;
  --shadow: 0 6px 20px rgba(35, 50, 90, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Noto Sans JP",
    "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}

body {
  background:
    radial-gradient(1200px 520px at 50% -8%, rgba(226, 35, 26, 0.14), transparent 62%),
    radial-gradient(900px 500px at 90% 8%, rgba(47, 111, 237, 0.10), transparent 60%),
    var(--bg);
  background-attachment: fixed;
  min-height: 100dvh;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding:
    calc(var(--safe-top) + 14px) 16px
    calc(var(--safe-bottom) + 28px);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

/* ---------- Header ---------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.brand { display: flex; align-items: center; gap: 11px; }
.brand-logo { filter: drop-shadow(0 2px 5px rgba(35,50,90,0.22)); }
.brand-text h1 { font-size: 17px; margin: 0; font-weight: 800; letter-spacing: .02em; }
.brand-text p { font-size: 11.5px; margin: 2px 0 0; color: var(--text-dim); }
.icon-btn {
  width: 38px; height: 38px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--bg-elev);
  color: var(--text-dim); font-size: 18px; font-weight: 700;
  cursor: pointer; box-shadow: var(--shadow);
}
.icon-btn:active { transform: scale(0.94); }
.header-actions { display: flex; gap: 8px; }
.icon-btn.notify-on { background: var(--red); border-color: var(--red); color: #fff; box-shadow: 0 3px 9px rgba(226,35,26,.3); }
.icon-btn.notify-off { opacity: .85; }

/* ---------- Hero ---------- */
.hero {
  background: linear-gradient(160deg, #ffffff, #f4f7fd);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 26px 20px;
  text-align: center;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow);
}
.hero-empty { color: var(--text-dim); }
.hero-mickey { opacity: .55; margin-bottom: 8px; }
.hero-empty p { margin: 0; font-weight: 700; color: var(--text); font-size: 15px; }
.hero-empty span { font-size: 12.5px; }

.hero-active { position: relative; z-index: 1; text-align: center; }
.hero-character {
  display: block; width: auto; max-width: 86%; max-height: 158px;
  margin: 0 auto 2px;
  filter: drop-shadow(0 4px 8px rgba(35,50,90,0.12));
}
/* 覗き込みイラスト（フォールバック）は横長なので上端から覗かせる */
.hero-character.is-fallback {
  width: min(300px, 86%); max-height: none; margin-top: -8px;
}
.hero-label { font-size: 12.5px; color: var(--text-dim); letter-spacing: .08em; }
.hero-count {
  font-size: clamp(40px, 14vw, 56px); font-weight: 800; line-height: 1.05; margin: 4px 0 4px;
  font-variant-numeric: tabular-nums; letter-spacing: .01em; color: var(--text);
}
.hero-time {
  font-size: 14px; font-weight: 700; color: var(--text-dim);
  font-variant-numeric: tabular-nums; margin-bottom: 2px;
}
.hero.ready .hero-time { color: var(--green); }
.hero-sub { font-size: 13px; color: var(--text-dim); }
.hero.ready { border-color: var(--green); background: linear-gradient(160deg, #f0fbf4, #e9f8ef); }
.hero.ready .hero-count { color: var(--green); }
.hero.ready .hero-label { color: var(--green); }
/* 残り時間プログレスバー */
.hero-ring {
  position: relative; height: 6px; border-radius: 99px;
  background: #e6e9f2; overflow: hidden;
  max-width: 240px; margin: 14px auto 0;
}
.hero-ring::after {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0;
  width: calc(var(--p, 0) * 1%); background: var(--red);
  border-radius: 99px; transition: width .5s linear;
}
.hero.ready .hero-ring::after { background: var(--green); }

/* ---------- Cards ---------- */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow);
}
.form-card { display: flex; flex-direction: column; gap: 14px; }

/* segmented control */
.seg {
  display: grid; grid-template-columns: 1fr 1fr; gap: 4px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: 12px; padding: 4px;
}
.seg-btn {
  min-height: 40px; border: none; background: transparent;
  color: var(--text-dim); font-size: 13.5px; font-weight: 700;
  border-radius: 9px; cursor: pointer; transition: background .15s, color .15s, box-shadow .15s;
}
.seg-btn.active { background: var(--red); color: #fff; box-shadow: 0 3px 9px rgba(226,35,26,.32); }

/* park segmented control（パーク選択） */
.seg.park .seg-btn.active[data-park="tdl"] { background: var(--tdl); box-shadow: 0 3px 9px rgba(47,111,237,.32); }
.seg.park .seg-btn.active[data-park="tds"] { background: var(--tds); box-shadow: 0 3px 9px rgba(15,157,150,.32); }

.seg-group-label { font-size: 12.5px; color: var(--text-dim); font-weight: 600; margin-bottom: -6px; }

/* fields */
.field { display: flex; flex-direction: column; gap: 6px; }
.field-label { font-size: 12.5px; color: var(--text-dim); font-weight: 600; }
.field-hint { font-size: 11.5px; color: var(--text-dim); }
.auto-tag {
  font-size: 10px; font-weight: 800; color: var(--green);
  background: rgba(22,163,74,.12); border-radius: 999px;
  padding: 1px 7px; margin-left: 4px; vertical-align: middle;
}
.opt-tag {
  font-size: 10px; font-weight: 700; color: var(--text-dim);
  background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: 999px;
  padding: 1px 7px; margin-left: 4px; vertical-align: middle;
}
.pass-reget {
  font-size: 11.5px; color: var(--text-dim); margin-top: 2px;
  display: flex; align-items: center; gap: 5px;
}
.pass-reget.ok { color: var(--green); font-weight: 700; }
input[type="text"], input[type="time"] {
  width: 100%; min-height: var(--tap);
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 16px; padding: 0 14px; font-family: inherit;
}
input[type="time"] { font-variant-numeric: tabular-nums; }
input:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(226,35,26,.12); }

/* プルダウン（アトラクション選択） */
.select {
  width: 100%; min-height: var(--tap);
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text);
  font-size: 16px; padding: 0 40px 0 14px; font-family: inherit; line-height: 1.3;
  -webkit-appearance: none; -moz-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath fill='%23707888' d='M4 6l4 4 4-4z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 14px center;
}
.select:focus { outline: none; border-color: var(--red); box-shadow: 0 0 0 3px rgba(226,35,26,.12); }

.row { display: flex; align-items: flex-end; gap: 10px; }
.grow { flex: 1; }
.now-btn {
  min-height: var(--tap); min-width: 60px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); color: var(--text);
  font-weight: 800; font-size: 14px; cursor: pointer;
}
.now-btn:active { transform: scale(0.96); }

.primary-btn {
  width: 100%; min-height: var(--tap);
  background: linear-gradient(180deg, #f0372f, var(--red-dim));
  color: #fff; border: none; border-radius: var(--radius-sm);
  font-size: 16px; font-weight: 800; cursor: pointer;
  box-shadow: 0 6px 18px rgba(226,35,26,.28);
}
.primary-btn:active { transform: translateY(1px); }

/* ---------- Lists ---------- */
.list-section { display: flex; flex-direction: column; gap: 10px; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-title { font-size: 14px; margin: 0; font-weight: 800; display: flex; align-items: center; gap: 8px; }
.count-badge {
  font-size: 11px; background: var(--bg-elev-2); color: var(--text-dim);
  border-radius: 999px; padding: 2px 8px; font-weight: 700; border: 1px solid var(--line);
}
.text-btn { background: none; border: none; color: var(--text-dim); font-size: 12.5px; cursor: pointer; }

.pass-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }

.pass {
  background: var(--bg-elev); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
  position: relative; overflow: hidden; box-shadow: var(--shadow);
}
.pass::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--blue);
}
.pass.dpa::before { background: var(--gold); }
.pass.ready { border-color: var(--green); }
.pass.ready::before { background: var(--green); }

.pass-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 10px; }
.pass-name { font-weight: 800; font-size: 15px; line-height: 1.3; }
.pass-name-row { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.pass-meta { font-size: 11.5px; color: var(--text-dim); margin-top: 3px; }
.pass-tags { display: flex; flex-direction: column; gap: 4px; align-items: flex-end; }
.tag {
  font-size: 10.5px; font-weight: 800; padding: 3px 8px; border-radius: 999px;
  background: rgba(47,111,237,.13); color: var(--blue); white-space: nowrap;
}
.tag.dpa { background: rgba(217,138,0,.15); color: var(--gold); }
.park-chip {
  font-size: 10.5px; font-weight: 800; padding: 2px 8px; border-radius: 999px; white-space: nowrap;
}
.park-chip.tdl { background: rgba(47,111,237,.13); color: var(--tdl); }
.park-chip.tds { background: rgba(15,157,150,.15); color: var(--tds); }

.pass-status { display: flex; align-items: baseline; gap: 10px; }
.pass-count {
  font-size: 30px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1;
}
.pass.ready .pass-count { color: var(--green); }
.pass-next { font-size: 12.5px; color: var(--text-dim); }

.pass-actions { display: flex; gap: 8px; }
.mini-btn {
  flex: 1; min-height: 40px; border-radius: 10px; cursor: pointer;
  border: 1px solid var(--line); background: var(--bg-elev-2);
  color: var(--text); font-size: 13px; font-weight: 700;
}
.mini-btn.danger { color: var(--text-dim); }
.mini-btn:active { transform: scale(0.97); }

.pass.history { opacity: .9; box-shadow: none; background: var(--bg-elev-2); }
.pass.history::before { background: #cfd6e4; }
.history .pass-name { font-size: 14px; }

/* ---------- 待ち時間パネル ---------- */
.wait-card { display: flex; flex-direction: column; gap: 10px; }
.wait-meta { font-size: 11.5px; color: var(--text-dim); }
.wait-meta.error { color: var(--red); }
.wait-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.wait-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--bg-elev-2); border: 1px solid var(--line);
  border-radius: var(--radius-sm); padding: 9px 12px; cursor: pointer;
  text-align: left; width: 100%; font-family: inherit;
}
.wait-row:active { transform: scale(0.99); }
.wait-time {
  min-width: 52px; text-align: center; font-weight: 800; font-size: 15px;
  font-variant-numeric: tabular-nums; color: var(--text); white-space: nowrap;
}
.wait-time .unit { font-size: 10px; font-weight: 700; color: var(--text-dim); margin-left: 1px; }
.wait-row.closed .wait-time { color: var(--text-dim); }
.wait-row.lv1 { border-left: 4px solid var(--green); }
.wait-row.lv2 { border-left: 4px solid var(--gold); }
.wait-row.lv3 { border-left: 4px solid var(--red); }
.wait-name { flex: 1; font-size: 13.5px; font-weight: 600; line-height: 1.3; }
.wait-closed-tag { font-size: 10.5px; color: var(--text-dim); font-weight: 700; }
.wait-settings { font-size: 12px; color: var(--text-dim); margin-top: 2px; }
.wait-settings summary { cursor: pointer; padding: 4px 0; }
.wait-settings code { background: var(--bg-elev-2); padding: 1px 5px; border-radius: 5px; font-size: 11px; }
.wait-settings .row { margin-top: 8px; }

/* ---------- Modal ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: flex-end; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(30,40,70,.4); backdrop-filter: blur(2px); }
.modal-sheet {
  position: relative; width: 100%; max-width: 520px;
  background: var(--bg-elev); border-top-left-radius: 22px; border-top-right-radius: 22px;
  padding: 10px 20px calc(var(--safe-bottom) + 24px);
  border: 1px solid var(--line); border-bottom: none;
  max-height: 86dvh; overflow-y: auto;
  animation: sheetUp .25s ease; box-shadow: 0 -8px 30px rgba(30,40,70,.18);
}
@keyframes sheetUp { from { transform: translateY(100%); } to { transform: translateY(0); } }
.modal-handle { width: 42px; height: 4px; background: var(--line); border-radius: 99px; margin: 6px auto 14px; }
.modal-sheet h2 { font-size: 17px; margin: 0 0 14px; }
.rule { background: var(--bg-elev-2); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; margin-bottom: 12px; }
.rule h3 { margin: 0 0 6px; font-size: 14px; }
.rule p { margin: 0 0 6px; font-size: 13px; color: var(--text-dim); }
.rule ul { margin: 0; padding-left: 18px; font-size: 13.5px; }
.rule li { margin: 4px 0; }
.rule b { color: var(--text); }
.modal-note { font-size: 11.5px; color: var(--text-dim); margin: 4px 0 18px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 20px);
  transform: translateX(-50%);
  background: #1f2533; color: #fff;
  border-radius: 999px;
  padding: 10px 18px; font-size: 13px; font-weight: 600;
  z-index: 60; box-shadow: 0 8px 24px rgba(30,40,70,.3);
  animation: toastIn .2s ease;
}
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

.app-footer { text-align: center; font-size: 11px; color: var(--text-dim); margin-top: 4px; display: flex; flex-direction: column; gap: 6px; }
.guide-link { color: var(--blue); font-weight: 700; font-size: 13px; text-decoration: none; }
.guide-link:active { opacity: .7; }
.guide-btn {
  display: block; text-align: center; text-decoration: none;
  background: var(--bg-elev-2); border: 1px solid var(--line); color: var(--text);
  border-radius: var(--radius-sm); padding: 12px; font-weight: 700; font-size: 14px; margin-bottom: 10px;
}
.guide-btn:active { transform: translateY(1px); }

@property --p { syntax: "<number>"; inherits: false; initial-value: 0; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
