:root {
  --bg: #1b1534;
  --bg2: #2a2150;
  --card: rgba(255, 255, 255, 0.08);
  --line: rgba(255, 255, 255, 0.16);
  --text: #f4f1ff;
  --muted: #b9b1d9;
  --accent: #ff5d8f;
  --gold: #ffd700;
  --warn: #ffb347;
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: radial-gradient(ellipse at top, var(--bg2), var(--bg) 70%) fixed;
  background-color: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Noto Sans JP", "Yu Gothic UI", sans-serif;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
}
input { -webkit-user-select: text; user-select: text; }
#view { min-height: 100%; }
button { font: inherit; color: inherit; }

/* ---- 共通部品 ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 46px; padding: 0 18px;
  border: 1px solid var(--line); border-radius: 14px;
  background: var(--card); color: var(--text);
  font-weight: 700; cursor: pointer; touch-action: manipulation;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--accent); border-color: transparent; color: #fff; }
.btn.big { min-height: 64px; font-size: 1.4rem; padding: 0 40px; border-radius: 20px; }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.9rem; border-radius: 10px; }
.btn.danger { color: #ff9aa9; }
.btn:disabled { opacity: 0.4; }
.icon-btn {
  width: 40px; height: 40px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--card); cursor: pointer; touch-action: manipulation;
}
.icon-btn:disabled { opacity: 0.3; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px 16px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }
.note { color: var(--muted); font-size: 0.85rem; line-height: 1.6; }
.warn { color: var(--warn); }
.empty { color: var(--muted); }

.toast {
  position: fixed; left: 50%; bottom: calc(24px + var(--safe-b)); transform: translate(-50%, 20px);
  background: rgba(0, 0, 0, 0.85); padding: 10px 18px; border-radius: 999px;
  opacity: 0; pointer-events: none; transition: 0.2s; z-index: 100; font-size: 0.95rem;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.bar {
  display: flex; align-items: center; gap: 12px;
  padding: calc(10px + var(--safe-t)) max(16px, var(--safe-r)) 10px max(16px, var(--safe-l));
  position: sticky; top: 0; background: rgba(27, 21, 52, 0.92); backdrop-filter: blur(6px); z-index: 5;
}
.bar h2 { margin: 0; font-size: 1.1rem; }
.page { max-width: 720px; margin: 0 auto; padding: 12px max(16px, var(--safe-r)) 40px max(16px, var(--safe-l)); display: flex; flex-direction: column; gap: 14px; }

/* ---- ホーム ---- */
.home {
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px;
  padding: calc(24px + var(--safe-t)) max(16px, var(--safe-r)) calc(24px + var(--safe-b)) max(16px, var(--safe-l)); text-align: center;
}
.logo { font-size: clamp(2.2rem, 8vw, 3.4rem); margin: 0; letter-spacing: 0.02em; font-weight: 900;
  background: linear-gradient(90deg, #ff5d8f, #ffb347, #7bdc8f, #4cc9f0); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo .ver { font-size: 0.8rem; color: var(--muted); -webkit-text-fill-color: var(--muted); margin-left: 8px; font-weight: 400; }
.tagline { margin: 0; color: var(--muted); }
.best { margin: 0; }
.best b { font-size: 1.3rem; color: var(--gold); }
.summary { max-width: 440px; line-height: 1.6; }

/* ---- プレイ ---- */
body[data-screen="play"] { overflow: hidden; }
.play {
  position: fixed; inset: 0;
  display: grid; grid-template-rows: auto 1fr auto;
  padding: var(--safe-t) var(--safe-r) var(--safe-b) var(--safe-l);
  touch-action: none;
}
.hud { display: flex; align-items: center; gap: 18px; padding: 8px 14px 4px; position: relative; }
.hud-item { display: flex; flex-direction: column; line-height: 1.1; min-width: 64px; }
.hud-item span { font-size: 0.65rem; color: var(--muted); letter-spacing: 0.1em; }
.hud-item b { font-size: 1.35rem; font-variant-numeric: tabular-nums; }
.hud-item.combo.hot b { color: var(--gold); text-shadow: 0 0 12px rgba(255, 215, 0, 0.6); }
.progress { position: absolute; left: 0; right: 0; bottom: 0; height: 3px; background: rgba(255,255,255,0.1); }
.progress i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #4cc9f0, #ff5d8f); }
.lane { width: 100%; height: 100%; display: block; min-height: 0; }
.pads {
  display: flex; justify-content: space-between; gap: 12px;
  padding: 8px 14px 12px; height: clamp(96px, 30vh, 170px);
}
.pad-group { display: flex; gap: 12px; flex: 0 1 46%; }
.pad {
  flex: 1; border-radius: 22px; border: 3px solid var(--c);
  background: color-mix(in srgb, var(--c) 22%, transparent);
  font-size: clamp(2rem, 9vh, 3.6rem); font-weight: 900; color: var(--c);
  touch-action: none; cursor: pointer; -webkit-touch-callout: none;
}
.pad.hit { animation: padhit 0.18s ease-out; }
@keyframes padhit {
  0% { background: var(--c); color: #1b1534; transform: scale(0.95); }
  100% { background: color-mix(in srgb, var(--c) 22%, transparent); color: var(--c); transform: scale(1); }
}
.rotate-hint {
  display: none; position: absolute; top: calc(56px + var(--safe-t)); left: 50%; transform: translateX(-50%);
  background: rgba(0,0,0,0.6); padding: 6px 14px; border-radius: 999px; font-size: 0.85rem; pointer-events: none;
}
@media (orientation: portrait) {
  .rotate-hint { display: block; }
  .pads { height: clamp(110px, 22vh, 200px); }
  .pad-group { flex-basis: 48%; gap: 8px; }
}

.overlay {
  position: fixed; inset: 0; background: rgba(10, 6, 25, 0.75);
  display: flex; align-items: center; justify-content: center; z-index: 50; padding: calc(16px + var(--safe-t)) calc(16px + var(--safe-r)) calc(16px + var(--safe-b)) calc(16px + var(--safe-l));
}
.overlay[hidden] { display: none; }
.overlay .card { display: flex; flex-direction: column; gap: 10px; min-width: 240px; background: var(--bg2); }
.overlay h2 { margin: 0 0 4px; text-align: center; }

/* ---- 結果 ---- */
.result {
  min-height: 100vh; min-height: 100dvh;
  display: flex; align-items: center; justify-content: center; gap: 40px; flex-wrap: wrap; padding: calc(20px + var(--safe-t)) calc(20px + var(--safe-r)) calc(20px + var(--safe-b)) calc(20px + var(--safe-l));
}
.rank { font-size: clamp(5rem, 22vh, 9rem); font-weight: 900; line-height: 1; animation: rankin 0.5s cubic-bezier(.2,1.6,.4,1); }
.rank-SS, .rank-S { color: var(--gold); text-shadow: 0 0 30px rgba(255,215,0,0.5); }
.rank-A { color: #ff5d8f; } .rank-B { color: #4cc9f0; } .rank-C { color: #7bdc8f; } .rank-D { color: var(--muted); }
@keyframes rankin { from { transform: scale(2.4); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.result-body { display: flex; flex-direction: column; gap: 14px; align-items: center; }
.result .score { font-size: 2.6rem; font-weight: 900; font-variant-numeric: tabular-nums; display: flex; flex-direction: column; align-items: center; }
.newbest { font-size: 0.9rem; color: var(--gold); }
.tally { border-collapse: collapse; min-width: 240px; }
.tally th { text-align: left; color: var(--muted); font-weight: 400; padding: 3px 18px 3px 0; }
.tally td { text-align: right; font-weight: 700; font-variant-numeric: tabular-nums; }

/* ---- メンバー ---- */
.members { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.member { display: flex; align-items: center; gap: 12px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 10px; }
.thumb { width: 56px; height: 56px; border-radius: 50%; overflow: hidden; flex: none; background: rgba(255,255,255,0.1); display: grid; place-items: center; color: var(--muted); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.info { flex: 1; min-width: 0; }
.name { font-weight: 800; font-size: 1.05rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name small { color: var(--muted); font-weight: 400; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 4px; }
.tag { font-size: 0.72rem; padding: 2px 8px; border-radius: 999px; background: rgba(255,255,255,0.1); color: var(--muted); }
.tag.main { background: rgba(76, 201, 240, 0.2); color: #9be6ff; }
.tag.rare { background: rgba(255, 215, 0, 0.2); color: var(--gold); }
.tag.hidden { background: rgba(0, 0, 0, 0.4); color: #ccc; }
.ops { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
@media (max-width: 520px) { .member { flex-wrap: wrap; } .ops { width: 100%; } }

.form h3 { margin: 10px 0 0; font-size: 1rem; color: var(--muted); border-bottom: 1px solid var(--line); padding-bottom: 4px; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: 0.9rem; color: var(--muted); }
.field.inline { flex-direction: row; align-items: center; justify-content: space-between; gap: 12px; }
.field input:not([type="range"]):not([type="checkbox"]) {
  font: inherit; color: var(--text); background: rgba(0,0,0,0.25); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; min-height: 44px;
}
.field.inline input[type="number"] { width: 110px; text-align: right; }
.field.inline input[type="range"] { width: 160px; }
.check { display: flex; align-items: center; gap: 10px; }
.check input { width: 22px; height: 22px; }
.check small { color: var(--muted); }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; align-self: flex-start; }
.seg button { border: 0; background: transparent; padding: 10px 18px; cursor: pointer; min-height: 42px; }
.seg button.on { background: var(--accent); color: #fff; font-weight: 700; }
.images { display: grid; grid-template-columns: repeat(auto-fill, minmax(84px, 1fr)); gap: 10px; }
.images .img { position: relative; aspect-ratio: 1; }
.images img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; border: 2px solid var(--line); }
.images .x { position: absolute; top: -4px; right: -4px; width: 28px; height: 28px; border-radius: 50%; border: 0; background: #000c; cursor: pointer; }
#f-add-label { align-self: flex-start; }

.cropper { align-items: center; max-width: min(92vw, 460px); max-height: 96vh; overflow: auto; }
.cropper canvas { width: min(80vw, 60vh, 380px); height: auto; aspect-ratio: 1; border-radius: 12px; touch-action: none; cursor: grab; }
.cropper input[type="range"] { width: min(80vw, 380px); }
.cropper .note { margin: 0; text-align: center; }
/* 横向きの低い画面では切り抜きを左右レイアウトに */
@media (max-height: 520px) and (orientation: landscape) {
  .overlay .cropper { max-width: 96vw; display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; align-items: center; }
  .cropper h2 { grid-column: 2; grid-row: 1; }
  .cropper canvas { grid-column: 1; grid-row: 1 / span 4; width: min(80vh, 46vw); }
  .cropper input[type="range"] { grid-column: 2; width: 100%; }
  .cropper .row { grid-column: 2; }
}
