:root {
  --bg: #1b1420;
  --panel: rgba(28, 20, 34, 0.88);
  --line: rgba(255, 255, 255, 0.14);
  --text: #fff7fb;
  --sub: #cdb9c8;
  --pink: #ff7eb3;
  --pink2: #ffb3d1;
  --danger: #ff6b6b;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: var(--bg); color: var(--text);
  font-family: -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
#app { position: fixed; inset: 0; }
#stage { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
.hidden { display: none !important; }
button {
  font: inherit; color: var(--text); background: rgba(255, 255, 255, 0.08);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px 14px; min-height: 44px;
  cursor: pointer; touch-action: manipulation;
}
button:active { transform: scale(0.97); background: rgba(255, 126, 179, 0.25); }

/* HUD */
#hud {
  position: absolute; top: calc(var(--safe-t) + 10px); left: calc(var(--safe-l) + 12px); right: calc(var(--safe-r) + 12px);
  display: flex; flex-direction: column; gap: 6px; pointer-events: none;
}
.name-plate { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 17px; text-shadow: 0 1px 4px #000a; }
.tier { font-size: 12px; font-weight: 600; padding: 2px 8px; border-radius: 99px; background: rgba(255, 126, 179, 0.3); border: 1px solid rgba(255, 126, 179, 0.6); }
.aff-bar { position: relative; width: min(60vw, 260px); height: 14px; border-radius: 99px; background: rgba(0, 0, 0, 0.45); border: 1px solid var(--line); overflow: hidden; }
#affFill { height: 100%; width: 0; background: linear-gradient(90deg, var(--pink), var(--pink2)); transition: width 0.5s ease; }
#affValue { position: absolute; right: 6px; top: -1px; font-size: 11px; font-weight: 700; text-shadow: 0 1px 2px #000; }

/* 会話 */
#dialog {
  position: absolute; left: calc(var(--safe-l) + 10px); right: calc(var(--safe-r) + 10px);
  bottom: calc(var(--safe-b) + 74px); min-height: 110px; padding: 12px 14px 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
#dialogName { font-size: 13px; color: var(--pink2); font-weight: 700; margin-bottom: 4px; }
#dialogText { font-size: 16px; line-height: 1.6; min-height: 52px; white-space: pre-wrap; }
#dialogNext { position: absolute; right: 14px; bottom: 4px; font-size: 12px; color: var(--sub); animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: 0.2; } }
#choices { display: flex; flex-direction: column; gap: 8px; margin-top: 8px; }
#choices button { text-align: left; background: rgba(255, 126, 179, 0.14); border-color: rgba(255, 126, 179, 0.5); }

/* 操作 */
#controls {
  position: absolute; left: calc(var(--safe-l) + 10px); right: calc(var(--safe-r) + 10px); bottom: calc(var(--safe-b) + 12px);
  display: flex; gap: 8px;
}
#controls button { flex: 1; background: var(--panel); font-weight: 700; }
#btnTalk { background: linear-gradient(135deg, #ff7eb3, #c25b8f) !important; border-color: transparent !important; }

#toast {
  position: absolute; left: 50%; top: calc(var(--safe-t) + 64px); transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); padding: 8px 14px; border-radius: 99px; font-size: 14px; white-space: nowrap;
}

/* パネル */
.panel {
  position: absolute; left: calc(var(--safe-l) + 12px); right: calc(var(--safe-r) + 12px); top: calc(var(--safe-t) + 50px);
  max-height: calc(100% - var(--safe-t) - var(--safe-b) - 70px); overflow-y: auto; -webkit-overflow-scrolling: touch;
  background: var(--panel); border: 1px solid var(--line); border-radius: 18px; padding: 14px 16px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
}
.panel h2 { margin: 0 0 10px; font-size: 18px; }
.row { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); font-size: 15px; }
.seg { display: flex; gap: 6px; }
.seg.wrap { flex-wrap: wrap; justify-content: flex-end; max-width: 62%; }
.seg button { min-width: 44px; padding: 8px 10px; }
.seg button.on { background: rgba(255, 126, 179, 0.4); border-color: var(--pink); }
button.small { padding: 8px 12px; }
button.danger { border-color: var(--danger); color: #ffd0d0; }
button.wide { width: 100%; margin-top: 12px; font-weight: 700; }
.ver { font-size: 12px; color: var(--sub); margin: 10px 0 0; }
#licenseBody { font-size: 13px; line-height: 1.6; color: var(--sub); }
#licenseBody b { color: var(--text); }

/* 読み込み・エラー */
#loading, #error {
  position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
  background: radial-gradient(circle at 50% 40%, #3a2340, #140e18); padding: 24px; text-align: center;
}
.logo { font-size: 40px; font-weight: 800; letter-spacing: 0.1em; color: var(--pink2); text-shadow: 0 0 18px rgba(255, 126, 179, 0.6); }
.sub { color: var(--sub); font-size: 13px; margin-bottom: 16px; }
.progress { width: min(70vw, 300px); height: 8px; background: rgba(255, 255, 255, 0.12); border-radius: 99px; overflow: hidden; }
#progFill { width: 0; height: 100%; background: linear-gradient(90deg, var(--pink), var(--pink2)); transition: width 0.2s; }
#progText { font-size: 13px; color: var(--sub); min-height: 1.4em; }
#error h2 { margin: 0; color: var(--danger); }
#errorMsg { margin: 0; line-height: 1.6; }
#errorDetail { max-width: 90vw; max-height: 30vh; overflow: auto; font-size: 11px; color: var(--sub); white-space: pre-wrap; text-align: left; }
#fps { position: absolute; right: calc(var(--safe-r) + 8px); top: calc(var(--safe-t) + 8px); font: 11px monospace; background: #0008; padding: 3px 6px; border-radius: 6px; pointer-events: none; }
