:root {
  --ink: #e8e4da;
  --dim: #9a968c;
  --bg: #050607;
  --panel: rgba(14, 16, 18, 0.94);
  --line: rgba(232, 228, 218, 0.18);
  --warn: #f2c94c;
  --red: #e0533d;
  --ok: #6fd28e;
  --paper: #ece6d6;
  --paper-ink: #2a2620;
  --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%; overflow: hidden; background: var(--bg); color: var(--ink); font-family: "BIZ UDPGothic", "Hiragino Sans", "Yu Gothic", sans-serif; -webkit-tap-highlight-color: transparent; touch-action: none; }
canvas#view { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
.hidden { display: none !important; }
.small { font-size: 13px; }
.dim { color: var(--dim); }
button { font: inherit; color: var(--ink); background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); border-radius: 6px; padding: 10px 16px; cursor: pointer; min-height: 44px; }
button:hover:not(:disabled) { background: rgba(255, 255, 255, 0.12); }
button:disabled { opacity: 0.45; cursor: default; }
button.primary { border-color: rgba(232, 228, 218, 0.5); background: rgba(232, 228, 218, 0.12); }
button.danger { border-color: rgba(224, 83, 61, 0.7); color: #ffd6cc; }
button.sel { outline: 2px solid var(--warn); }

/* ---- HUD ---- */
#hud { position: fixed; inset: 0; pointer-events: none; }
#objective { position: absolute; top: calc(12px + var(--safe-t)); left: calc(14px + var(--safe-l)); max-width: min(560px, 70vw); font-size: 15px; line-height: 1.5; padding: 6px 10px; background: rgba(0, 0, 0, 0.45); border-left: 3px solid var(--ink); text-shadow: 0 1px 2px #000; }
#objective .lbl { color: var(--dim); }
#objective.flash { animation: obj 1.4s ease-out; }
@keyframes obj { from { border-left-color: var(--warn); background: rgba(60, 50, 10, 0.6); } }
#crosshair { position: absolute; left: 50%; top: 50%; width: 6px; height: 6px; margin: -3px 0 0 -3px; border-radius: 50%; background: rgba(255, 255, 255, 0.7); box-shadow: 0 0 2px #000; }
#crosshair.on { width: 10px; height: 10px; margin: -5px 0 0 -5px; background: transparent; border: 2px solid var(--ink); }
#prompt { position: absolute; left: 50%; top: calc(50% + 22px); transform: translateX(-50%); font-size: 15px; white-space: nowrap; text-shadow: 0 1px 3px #000; padding: 3px 10px; background: rgba(0, 0, 0, 0.35); border-radius: 4px; }
#prompt:empty { display: none; }
#talk { position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(150px + var(--safe-b)); display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: rgba(0, 0, 0, 0.55); border: 1px solid var(--line); border-radius: 6px; font-size: 14px; }
#talk-ring { width: 36px; height: 36px; }
#talk-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); }
#talk-ring .bg { fill: none; stroke: rgba(255, 255, 255, 0.15); stroke-width: 4; }
#talk-ring .fg { fill: none; stroke: var(--warn); stroke-width: 4; stroke-dasharray: 106.8; stroke-dashoffset: 106.8; }
#warnframe { position: absolute; inset: 10px; border: 3px solid var(--warn); border-radius: 8px; display: flex; align-items: flex-end; justify-content: center; padding-bottom: 210px; color: var(--warn); font-size: 16px; text-shadow: 0 1px 3px #000; }
#toast { position: absolute; left: 50%; top: 64%; transform: translateX(-50%); max-width: min(640px, 90vw); text-align: center; font-size: 15px; line-height: 1.6; padding: 8px 14px; background: rgba(0, 0, 0, 0.6); border-radius: 6px; opacity: 0; transition: opacity 0.25s; }
#toast.on { opacity: 1; }
#subs { position: absolute; left: 50%; bottom: calc(26px + var(--safe-b)); transform: translateX(-50%); width: min(760px, 94vw); display: flex; flex-direction: column; align-items: center; gap: 4px; }
.sub-line { display: flex; align-items: center; gap: 8px; font-family: "Zen Old Mincho", serif; font-size: 18px; line-height: 1.5; padding: 4px 12px; background: rgba(0, 0, 0, 0.62); border-radius: 4px; text-shadow: 0 1px 2px #000; animation: subIn 0.2s ease-out; }
.sub-line .src { font-family: "BIZ UDPGothic", sans-serif; font-size: 13px; color: var(--dim); white-space: nowrap; }
.sub-line .wave { display: inline-flex; gap: 2px; align-items: center; height: 16px; }
.sub-line .wave i { width: 3px; background: var(--ink); animation: wave 0.5s infinite alternate; }
.sub-line .wave i:nth-child(2) { animation-delay: 0.1s; } .sub-line .wave i:nth-child(3) { animation-delay: 0.2s; } .sub-line .wave i:nth-child(4) { animation-delay: 0.3s; }
.sub-line .arrow { display: inline-block; font-family: sans-serif; font-size: 15px; width: 18px; text-align: center; }
.sub-line.alarm { border-left: 4px solid var(--red); }
.sub-line.alarm .src::before { content: "◉ "; color: var(--red); }
.sub-line.self { color: #d8e8ff; }
@keyframes wave { from { height: 3px; } to { height: 15px; } }
@keyframes subIn { from { opacity: 0; transform: translateY(6px); } }
#debug { position: absolute; right: 8px; top: 8px; font: 11px/1.4 monospace; background: rgba(0, 0, 0, 0.7); padding: 6px 8px; white-space: pre; max-width: 46vw; }

/* ---- touch ---- */
#touch { position: fixed; inset: 0; pointer-events: none; }
#t-look { position: absolute; right: 0; top: 0; width: 60%; height: 100%; pointer-events: auto; }
#t-stick { position: absolute; left: calc(24px + var(--safe-l)); bottom: calc(28px + var(--safe-b)); width: 130px; height: 130px; border-radius: 50%; background: rgba(255, 255, 255, 0.07); border: 1px solid var(--line); pointer-events: auto; }
#t-knob { position: absolute; left: 50%; top: 50%; width: 54px; height: 54px; margin: -27px 0 0 -27px; border-radius: 50%; background: rgba(255, 255, 255, 0.22); }
#t-buttons { position: absolute; right: calc(16px + var(--safe-r)); bottom: calc(20px + var(--safe-b)); display: grid; grid-template-columns: repeat(2, 76px); gap: 10px; pointer-events: auto; }
#t-buttons button { min-height: 52px; padding: 6px; font-size: 14px; background: rgba(0, 0, 0, 0.45); }
#t-buttons button.big { grid-column: span 2; min-height: 64px; font-size: 16px; }
#t-buttons button.on { background: rgba(232, 228, 218, 0.25); }
#t-pause { position: absolute; right: calc(12px + var(--safe-r)); top: calc(12px + var(--safe-t)); pointer-events: auto; min-height: 44px; width: 48px; padding: 0; background: rgba(0, 0, 0, 0.45); }
body.touch #talk { bottom: calc(220px + var(--safe-b)); }
body.touch #objective { max-width: calc(100vw - 90px); font-size: 14px; }
body.touch #warnframe { padding-bottom: 260px; }

/* ---- title / screens ---- */
.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 30%, rgba(30, 36, 44, 0.75), rgba(0, 0, 0, 0.96) 70%); overflow-y: auto; padding: 16px; }
#title { background-size: cover; background-position: center; }
#title::before { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.88) 70%); }
.title-inner { position: relative; max-width: 560px; width: 100%; text-align: center; }
.series { font-size: 13px; color: var(--dim); letter-spacing: 0.1em; }
h1 { font-family: "Zen Old Mincho", serif; font-size: clamp(44px, 12vw, 78px); margin: 8px 0 0; letter-spacing: 0.18em; font-weight: 700; text-shadow: 0 0 24px rgba(224, 83, 61, 0.35); }
.sub { font-family: "Zen Old Mincho", serif; font-size: 18px; color: var(--dim); margin-bottom: 18px; }
.lead { font-size: 15px; line-height: 1.8; margin: 0 0 18px; }
#title-buttons { display: flex; flex-direction: column; gap: 10px; max-width: 320px; margin: 0 auto 14px; }

/* ---- modal ---- */
#modal { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.55); padding: 12px; z-index: 5; }
#modal-box { width: min(640px, 100%); max-height: calc(100% - 8px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line); border-radius: 8px; }
#modal-head { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 10px 12px; border-bottom: 1px solid var(--line); font-size: 16px; }
#modal-close { min-height: 40px; padding: 6px 12px; }
#modal-body { padding: 14px; overflow-y: auto; line-height: 1.7; font-size: 15px; }
#modal-foot { padding: 8px 12px; color: var(--dim); border-top: 1px solid var(--line); }
#modal-foot:empty { display: none; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin: 10px 0; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.grid6 { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px; }
.grid6 button { padding: 14px 0; font-size: 18px; font-weight: 700; }
.lamp { display: inline-block; width: 10px; height: 10px; border-radius: 50%; background: #333; margin-right: 6px; vertical-align: middle; }
.lamp.on { background: var(--ok); box-shadow: 0 0 6px var(--ok); }
.lamp.red { background: var(--red); box-shadow: 0 0 6px var(--red); }
.status { padding: 8px 10px; background: rgba(0, 0, 0, 0.35); border-radius: 4px; min-height: 2.4em; }
.status.bad { color: #ffc8bc; }
.status.good { color: #c8f0d4; }
.logs button { display: block; width: 100%; text-align: left; font-family: monospace; font-size: 14px; margin: 4px 0; min-height: 40px; }
.logs button.picked { border-color: var(--ok); }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; max-width: 300px; margin: 8px auto; }
.keypad button { font-size: 20px; padding: 12px 0; }
.display { font-family: monospace; font-size: 30px; letter-spacing: 0.4em; text-align: center; padding: 10px; background: #0a0c0a; color: var(--ok); border-radius: 4px; margin: 0 auto 6px; max-width: 300px; }
.toggle-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.toggle-row button { min-width: 84px; }
.toggle-row button.on { border-color: var(--ok); color: #c8f0d4; }
.slots { display: flex; gap: 8px; justify-content: center; margin: 10px 0; }
.slots div { width: 30%; min-height: 64px; border: 1px dashed var(--line); border-radius: 6px; display: flex; align-items: center; justify-content: center; text-align: center; font-size: 13px; padding: 4px; }
.wavebox { height: 26px; display: block; margin: 4px 0; }
.hold-btn { width: 100%; min-height: 64px; font-size: 17px; position: relative; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; }
.hold-btn .fill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; background: rgba(242, 201, 76, 0.28); pointer-events: none; }
.hold-btn.warn { border-color: var(--warn); }

/* documents */
.paper { background: var(--paper); color: var(--paper-ink); font-family: "Zen Old Mincho", serif; font-size: 17px; line-height: 1.95; padding: 22px 20px; border-radius: 3px; box-shadow: 0 6px 30px rgba(0, 0, 0, 0.6); position: relative; background-image: radial-gradient(circle at 20% 15%, rgba(140, 110, 60, 0.12), transparent 40%), radial-gradient(circle at 80% 90%, rgba(120, 90, 50, 0.14), transparent 45%); }
.paper.thermal { background: #f2f0ea; font-family: monospace; font-size: 15px; }
.paper.letter { font-family: "Zen Kurenaido", serif; font-size: 19px; }
.paper.memo { background: #f4eaa8; font-family: "Zen Kurenaido", serif; }
.paper .ptitle { font-weight: 700; font-size: 15px; color: #5a5040; border-bottom: 1px solid rgba(60, 50, 30, 0.25); margin-bottom: 10px; }
.paper img { width: 100%; display: block; margin: 0 0 12px; border: 6px solid #f6f2e8; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.35); filter: sepia(0.25) contrast(0.95); }
.paper .hand { position: absolute; right: -6px; bottom: 20px; width: 70px; height: 90px; opacity: 0.0; background: radial-gradient(ellipse at 50% 60%, rgba(40, 50, 60, 0.45), transparent 60%); border-radius: 40% 40% 30% 30%; transition: opacity 0.6s; }
.paper .hand.on { opacity: 1; }
.think { margin-top: 12px; color: #cfe0ff; font-size: 15px; }
.think::before { content: "結衣 ― "; color: var(--dim); }

/* inventory */
.inv { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.inv button { text-align: left; font-size: 14px; min-height: 52px; }
.inv-desc { margin-top: 10px; }
.replylog { margin-top: 14px; font-size: 13px; }
.replylog li { margin: 2px 0; }

/* fade / death / ending */
#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity 0.6s; z-index: 4; }
#fade.on { opacity: 1; }
#death { position: fixed; inset: 0; z-index: 6; display: flex; align-items: center; justify-content: center; background: rgba(0, 0, 0, 0.0); }
#death-text { font-family: "Zen Old Mincho", serif; font-size: 34px; letter-spacing: 0.3em; text-shadow: 0 0 10px #000; }
#ending { flex-direction: column; justify-content: flex-start; padding-top: 32px; background: #000; z-index: 7; }
#ending-img { width: min(900px, 100%); aspect-ratio: 16 / 9; background-size: cover; background-position: center; opacity: 0; transition: opacity 2.5s; border-radius: 2px; }
#ending-img.on { opacity: 1; }
#ending-text { width: min(760px, 100%); font-family: "Zen Old Mincho", serif; font-size: 18px; line-height: 2; margin-top: 18px; min-height: 9em; }
#ending-text p { opacity: 0; transition: opacity 1.4s; margin: 0 0 6px; }
#ending-text p.on { opacity: 1; }
#ending-text p.last { margin-top: 18px; font-size: 21px; font-weight: 700; }
#ending-skip { margin-top: 16px; }
#result { z-index: 8; }
.result-inner { width: min(620px, 100%); text-align: center; }
.result-code { font-size: 13px; color: var(--dim); letter-spacing: 0.2em; }
#result-title { font-family: "Zen Old Mincho", serif; font-size: 30px; margin: 6px 0; }
.result-line { font-family: "Zen Old Mincho", serif; margin-bottom: 14px; }
.result-stats { display: flex; justify-content: center; gap: 18px; flex-wrap: wrap; margin-bottom: 14px; }
.result-stats div { background: rgba(255, 255, 255, 0.06); padding: 8px 14px; border-radius: 6px; }
.result-stats b { display: block; font-size: 22px; }
.end-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin: 10px 0 16px; font-size: 13px; }
.end-list div { padding: 8px 4px; border: 1px solid var(--line); border-radius: 4px; }
.end-list div.got { border-color: rgba(232, 228, 218, 0.6); background: rgba(232, 228, 218, 0.08); }
.end-list div.now { outline: 2px solid var(--warn); }
.share-row { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 8px 0 14px; }
.result-buttons { margin-top: 8px; }
#rotate-hint { position: fixed; left: 50%; top: 40%; transform: translateX(-50%); background: rgba(0, 0, 0, 0.7); padding: 8px 14px; border-radius: 6px; font-size: 13px; pointer-events: none; z-index: 3; }
.settings label { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--line); }
.settings input[type="range"] { width: 50%; }
.settings select { font: inherit; background: #111; color: var(--ink); border: 1px solid var(--line); padding: 6px; border-radius: 4px; }
@media (max-width: 480px) {
  #modal-body { padding: 10px; font-size: 14px; }
  .paper { font-size: 16px; padding: 16px 14px; }
  .end-list { grid-template-columns: repeat(2, 1fr); }
  .grid6 { grid-template-columns: repeat(3, 1fr); }
  .sub-line { font-size: 16px; }
}
/* share (from game-kit kit.css, dark) */
.share-text { font-size: 0.85em; background: rgba(255, 255, 255, 0.06); border: 1px solid var(--line); padding: 8px 10px; border-radius: 8px; text-align: left; }
.share-buttons { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; margin: 10px 0 6px; }
.share-buttons button { padding: 9px 6px; border-radius: 10px; }
.share-buttons .share-x { background: #000; color: #fff; border-color: #444; }
.share-buttons .share-fb { background: #1b4f9a; color: #fff; border-color: #1b4f9a; }
.share-buttons .share-line { background: #06a04a; color: #fff; border-color: #06a04a; }
.share-buttons .share-ig { background: linear-gradient(45deg, #f2a43a, #d9406a, #7a46c8); color: #fff; border: none; }
.share-note { min-height: 1.4em; color: var(--warn); font-size: 0.9em; }
body.bigsubs .sub-line { font-size: 22px; }
body.touch #subs { bottom: calc(250px + var(--safe-b)); width: calc(100vw - 24px); }
body.touch #toast { top: 30%; }
@media (orientation: landscape) and (pointer: coarse) { body.touch #subs { bottom: calc(12px + var(--safe-b)); width: 46vw; left: 50%; } }
