:root {
  --red: #b31b1b;
  --red-dark: #7d1212;
  --cream: #f6f1e7;
  --ink: #1f1a17;
  --glass: rgba(20, 16, 14, 0.58);
  --line: rgba(255, 255, 255, 0.14);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0c0a09; color: var(--cream); font-family: var(--sans); -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas#view { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; outline: none; }
[hidden] { display: none !important; }
kbd { display: inline-block; min-width: 1.5em; padding: 0.05em 0.4em; border: 1px solid rgba(255,255,255,0.35); border-bottom-width: 2px; border-radius: 5px; font: 600 0.78em/1.4 var(--sans); text-align: center; background: rgba(255,255,255,0.08); color: inherit; }
button { font: inherit; color: inherit; cursor: pointer; }

.screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; z-index: 20; }
.screen.dim { background: rgba(10, 8, 7, 0.55); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.screen.side { justify-content: flex-start; padding-left: max(4vw, 20px); }

.wordmark { font: 400 clamp(44px, 8vw, 104px)/0.95 var(--serif); letter-spacing: -0.02em; margin: 0; color: #fff; text-shadow: 0 2px 30px rgba(0,0,0,0.45); }
.wordmark span { display: block; font-style: italic; color: #ffd9d0; }
.kicker { text-transform: uppercase; letter-spacing: 0.22em; font-size: 12px; font-weight: 600; color: #ffd2c4; margin: 0 0 14px; }
.sub { font: italic 20px/1.4 var(--serif); color: #f3e9dc; margin: 18px 0 30px; max-width: 30ch; }
.fine { font-size: 12px; line-height: 1.5; color: rgba(246,241,231,0.65); max-width: 52ch; }

#loading { background: radial-gradient(ellipse at 50% 30%, #3a1512, #0c0a09 70%); }
.loading-box { width: min(520px, 86vw); }
.loading-box .wordmark { font-size: clamp(40px, 7vw, 76px); margin-bottom: 34px; }
.bar { height: 3px; background: rgba(255,255,255,0.12); border-radius: 2px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--red); transition: width 0.3s; box-shadow: 0 0 12px var(--red); }
#loadText { font-size: 13px; color: #cdbfae; margin-top: 12px; }

#title { justify-content: flex-start; padding-left: max(6vw, 24px); background: linear-gradient(90deg, rgba(10,6,5,0.72) 0%, rgba(10,6,5,0.25) 45%, rgba(0,0,0,0) 70%); }
.title-box { max-width: 560px; animation: rise 1.2s ease-out both; }
.title-buttons { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 28px; }
@keyframes rise { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }

.btn { border: 1px solid rgba(255,255,255,0.3); background: rgba(255,255,255,0.08); padding: 11px 20px; border-radius: 999px; font-weight: 600; font-size: 15px; transition: background 0.15s, transform 0.1s; backdrop-filter: blur(6px); }
.btn:hover { background: rgba(255,255,255,0.18); }
.btn:active { transform: scale(0.97); }
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; box-shadow: 0 6px 24px rgba(179,27,27,0.35); }
.btn.primary:hover { background: #c62525; }

.panel { background: rgba(24, 19, 17, 0.86); border: 1px solid var(--line); border-radius: 18px; padding: 26px 28px; width: min(430px, 92vw); max-height: 92vh; overflow: auto; backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px); box-shadow: 0 20px 60px rgba(0,0,0,0.45); }
.panel.wide { width: min(780px, 94vw); }
.panel h2 { font: 400 30px var(--serif); margin: 0 0 18px; }
.field { display: block; font-size: 12px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: #cdbfae; margin-bottom: 16px; }
.field input[type=text], .field input:not([type]), .field select { display: block; width: 100%; margin-top: 7px; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255,255,255,0.07); color: #fff; font: 500 15px var(--sans); text-transform: none; letter-spacing: 0; }
.field select option { color: #111; }
.field input[type=range] { display: block; width: 100%; margin-top: 8px; accent-color: var(--red); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { border: 1px solid var(--line); background: rgba(255,255,255,0.05); border-radius: 999px; padding: 6px 11px; font: 500 13px var(--sans); text-transform: none; letter-spacing: 0; color: #eee; }
.chip.on { background: var(--red); border-color: var(--red); color: #fff; }
.swatches { display: flex; gap: 7px; margin-top: 8px; flex-wrap: wrap; }
.sw { width: 28px; height: 28px; border-radius: 50%; border: 2px solid rgba(255,255,255,0.25); padding: 0; }
.sw.on { border-color: #fff; box-shadow: 0 0 0 2px var(--red); }
.row { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 10; }
#hud.hidden > *:not(#toasts):not(#dialog) { display: none; }
#topleft { position: absolute; top: 18px; left: 20px; text-shadow: 0 1px 6px rgba(0,0,0,0.6); }
#dateLine { font-size: 12px; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: #ffd9cc; }
#clock { font: 400 40px/1.05 var(--serif); }
#place { font-size: 14px; color: #f1e7da; margin-top: 2px; }
#goals { position: absolute; top: 118px; left: 20px; width: min(330px, 44vw); background: var(--glass); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
#goals h3 { font: 600 11px var(--sans); letter-spacing: 0.14em; text-transform: uppercase; margin: 0 0 8px; color: #ffcfc2; }
#goalList { list-style: none; margin: 0; padding: 0; }
#goalList li { display: flex; gap: 8px; font-size: 13.5px; line-height: 1.35; padding: 4px 0; color: #efe6d8; }
#goalList li::before { content: ""; flex: none; width: 12px; height: 12px; margin-top: 3px; border-radius: 3px; border: 1.5px solid rgba(255,255,255,0.55); }
#goalList li.done { color: rgba(239,230,216,0.5); text-decoration: line-through; }
#goalList li.done::before { background: var(--red); border-color: var(--red); }
#goalList li.next::before { border-color: #f1c35b; box-shadow: 0 0 8px #f1c35b; }
#goalList li span { flex: 1; }
#goalList li em { font-style: normal; color: #f1c35b; font-size: 12px; white-space: nowrap; }
#mapWrap { position: absolute; top: 16px; right: 16px; width: 200px; height: 200px; border-radius: 50%; box-shadow: 0 6px 30px rgba(0,0,0,0.45), 0 0 0 3px rgba(255,255,255,0.85); overflow: visible; }
#minimap { width: 200px; height: 200px; border-radius: 50%; display: block; }
#mapWrap .north { position: absolute; transform: translate(-50%, -50%); width: 20px; height: 20px; line-height: 20px; text-align: center; border-radius: 50%; background: var(--red); color: #fff; font: 700 11px var(--sans); }
#stats { position: absolute; left: 20px; bottom: 20px; width: 250px; background: var(--glass); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px); }
.stat { display: grid; grid-template-columns: 62px 1fr; align-items: center; gap: 8px; font-size: 12px; margin-bottom: 6px; color: #e8ddd0; }
.stat i { height: 6px; border-radius: 3px; background: rgba(255,255,255,0.12); overflow: hidden; display: block; }
.stat b { display: block; height: 100%; border-radius: 3px; transition: width 0.4s; }
.stat.energy b { background: #f1c35b; }
.stat.social b { background: #6fc3e8; }
.stat.spirit b { background: #e0453b; }
.stat.warmth b { background: #ff8a4c; }
.statline { display: flex; justify-content: space-between; font-size: 12px; color: #cdbfae; margin-top: 8px; }
.statline b { color: #fff; font-size: 14px; }
#prompt { position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); background: rgba(250, 246, 238, 0.94); color: var(--ink); padding: 10px 18px; border-radius: 999px; font-weight: 600; font-size: 15px; box-shadow: 0 8px 30px rgba(0,0,0,0.35); white-space: nowrap; }
#prompt kbd { border-color: rgba(0,0,0,0.35); background: var(--red); color: #fff; margin-right: 6px; }
#toasts { position: absolute; top: 18px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; align-items: center; width: min(460px, 60vw); }
.toast { background: rgba(250, 246, 238, 0.95); color: var(--ink); border-radius: 14px; padding: 10px 16px; box-shadow: 0 8px 30px rgba(0,0,0,0.3); animation: toastIn 0.35s ease-out both; width: 100%; border-left: 4px solid var(--red); }
.toast b { display: block; font: 600 15px var(--serif); margin-bottom: 2px; }
.toast span { font-size: 13px; line-height: 1.4; color: #4a3f38; }
.toast.out { animation: toastOut 0.5s ease-in forwards; }
@keyframes toastIn { from { opacity: 0; transform: translateY(-10px); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(-10px); } }
#dialog { position: absolute; left: 50%; bottom: 40px; transform: translateX(-50%); width: min(640px, 92vw); background: rgba(250, 246, 238, 0.97); color: var(--ink); border-radius: 18px; padding: 16px 20px; pointer-events: auto; box-shadow: 0 12px 40px rgba(0,0,0,0.4); animation: toastIn 0.25s ease-out; }
#dlgName { font: 600 17px var(--serif); color: var(--red-dark); }
#dlgText { margin: 6px 0 12px; font-size: 15px; line-height: 1.5; }
#dlgButtons { display: flex; flex-wrap: wrap; gap: 8px; }
#dialog .btn { color: var(--ink); border-color: rgba(0,0,0,0.2); background: rgba(0,0,0,0.04); padding: 8px 14px; font-size: 14px; }
#dialog .btn kbd { border-color: rgba(0,0,0,0.3); }
#dialog .btn.primary { background: var(--red); color: #fff; }
#keys { position: absolute; right: 18px; bottom: 16px; font-size: 12px; color: rgba(255,255,255,0.75); text-shadow: 0 1px 4px rgba(0,0,0,0.7); max-width: 520px; text-align: right; line-height: 1.9; }

#chapterCard { position: fixed; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; pointer-events: none; z-index: 15; background: radial-gradient(ellipse at center, rgba(10,6,5,0.55), rgba(10,6,5,0) 65%); }
#chapterCard h1 { font: 400 clamp(48px, 8vw, 96px)/1 var(--serif); margin: 0 0 14px; text-shadow: 0 2px 30px rgba(0,0,0,0.5); }
#chapterCard p:last-child { font: italic 19px/1.45 var(--serif); max-width: 46ch; margin: 0; color: #f3e9dc; text-shadow: 0 1px 10px rgba(0,0,0,0.6); }
#chapterCard.show { animation: card 6.5s ease both; }
@keyframes card { 0% { opacity: 0; transform: scale(0.98); } 10% { opacity: 1; transform: none; } 82% { opacity: 1; } 100% { opacity: 0; } }

#mapScreen { flex-direction: column; padding: 20px; }
.map-head { text-align: center; margin-bottom: 10px; }
.map-head h2 { font: 400 28px var(--serif); margin: 0; }
.map-head p { margin: 4px 0 0; font-size: 13px; color: #d8ccbd; }
.map-frame { flex: 1; width: 100%; display: flex; align-items: center; justify-content: center; min-height: 0; }
#bigmap { border-radius: 14px; box-shadow: 0 20px 60px rgba(0,0,0,0.5); cursor: pointer; }

.tabs { display: flex; gap: 6px; margin-bottom: 16px; flex-wrap: wrap; }
.tabs button { border: 1px solid var(--line); background: transparent; border-radius: 999px; padding: 7px 14px; font-size: 14px; }
.tabs button.on { background: var(--red); border-color: var(--red); }
#jBody { min-height: 260px; font-size: 14px; line-height: 1.55; }
#jBody h3 { font: 400 24px var(--serif); margin: 0 0 6px; }
#jBody h4 { font: 600 12px var(--sans); text-transform: uppercase; letter-spacing: 0.12em; color: #cdbfae; margin: 18px 0 6px; }
.jlist { padding-left: 18px; margin: 8px 0; }
.jlist li.done { color: rgba(246,241,231,0.5); text-decoration: line-through; }
.jplaces { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 10px; max-height: 52vh; overflow: auto; }
.jplaces li { background: rgba(255,255,255,0.05); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.jplaces li b { display: block; font: 600 15px var(--serif); margin-bottom: 3px; }
.jplaces li span { font-size: 12.5px; color: #d6cabb; }
.jplaces li.locked { opacity: 0.4; }
.report { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-top: 14px; }
.report div { background: rgba(255,255,255,0.05); border: 1px solid var(--line); border-radius: 12px; padding: 12px; }
.report span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: 0.12em; color: #cdbfae; }
.report b { display: block; font: 400 32px var(--serif); margin: 4px 0; }
.report em { font-style: normal; font-size: 12px; color: #d6cabb; }
.bellgrid { display: grid; grid-template-columns: repeat(7, 34px); gap: 10px; margin-top: 16px; }
.bellgrid i { width: 34px; height: 34px; border-radius: 50% 50% 20% 20%; background: rgba(255,255,255,0.1); border: 1px solid var(--line); }
.bellgrid i.on { background: linear-gradient(#f3d27a, #b98a2e); box-shadow: 0 0 12px rgba(243,210,122,0.6); }

#photo { position: fixed; left: 0; right: 0; bottom: 18px; display: flex; justify-content: center; z-index: 12; }
.photo-bar { display: flex; gap: 10px; align-items: center; background: var(--glass); border: 1px solid var(--line); border-radius: 999px; padding: 8px 10px 8px 18px; backdrop-filter: blur(8px); font-weight: 600; font-size: 14px; }
.photo-bar select { background: rgba(255,255,255,0.1); color: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 8px 10px; }
.photo-bar select option { color: #111; }

#mini { background: #120f0d; z-index: 30; flex-direction: column; }
.mg-head { position: absolute; top: 18px; left: 0; right: 0; text-align: center; pointer-events: none; z-index: 2; }
.mg-head h2 { font: 400 28px var(--serif); margin: 0; }
.mg-head p { font-size: 14px; color: #cdbfae; margin: 6px 0 0; }
.mg-canvas { width: 100%; height: 100%; display: block; touch-action: none; }
.mg-foot { position: absolute; bottom: 30px; left: 0; right: 0; display: flex; justify-content: center; gap: 30px; }
.pad { width: 120px; height: 80px; border-radius: 18px; border: 1px solid var(--line); background: rgba(255,255,255,0.08); font-weight: 700; letter-spacing: 0.1em; touch-action: none; }
.pad:active { background: var(--red); }
.mg-result { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; background: rgba(12,9,8,0.82); padding: 20px; z-index: 3; animation: toastIn 0.3s; }
.mg-result h3 { font: 400 40px var(--serif); margin: 0 0 12px; }
.mg-result p { margin: 4px 0; color: #ddd1c2; max-width: 48ch; }
.mg-result .btn { margin-top: 20px; }
.quiz { width: min(680px, 92vw); margin: auto; }
.quiz-top { display: flex; justify-content: space-between; align-items: baseline; }
.quiz-top h2 { font: 400 28px var(--serif); margin: 0; }
.quiz-count { color: #cdbfae; }
.quiz-timer { height: 4px; background: rgba(255,255,255,0.1); border-radius: 2px; margin: 14px 0 22px; overflow: hidden; }
.quiz-timer i { display: block; height: 100%; background: var(--red); }
.quiz-q { font: 400 24px/1.35 var(--serif); margin: 0 0 20px; }
.quiz-a { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.btn.answer { border-radius: 14px; text-align: left; padding: 14px 16px; font-weight: 500; }
.btn.answer.right { background: #2d7a46; border-color: #2d7a46; }
.btn.answer.wrong { background: var(--red); border-color: var(--red); }
.btn.answer.dim { opacity: 0.45; }
.quiz-hint { font-size: 12px; color: #9d9282; margin-top: 16px; }

#fade { position: fixed; inset: 0; background: #000; opacity: 0; pointer-events: none; transition: opacity 0.45s; z-index: 25; }
#fade.on { opacity: 1; }
#fade.flash { background: #fff; opacity: 0.8; transition: none; }

#touch { position: fixed; inset: 0; pointer-events: none; z-index: 11; }
#stick { position: absolute; left: 24px; bottom: 150px; width: 130px; height: 130px; border-radius: 50%; background: rgba(255,255,255,0.12); border: 1px solid rgba(255,255,255,0.3); pointer-events: auto; touch-action: none; }
#stick i { position: absolute; left: 50%; top: 50%; width: 56px; height: 56px; margin: -28px; border-radius: 50%; background: rgba(255,255,255,0.55); }
#touchButtons { position: absolute; right: 16px; bottom: 150px; display: grid; grid-template-columns: repeat(3, 58px); gap: 10px; pointer-events: auto; }
#touchButtons button { height: 58px; border-radius: 50%; border: 1px solid rgba(255,255,255,0.35); background: rgba(20,16,14,0.5); font-weight: 700; font-size: 13px; touch-action: none; }
#touchButtons button[data-t=e] { background: var(--red); }
#touchButtons button.on { background: #f1c35b; color: #111; }

@media (max-width: 760px) {
  #keys { display: none; }
  #goals { top: 96px; width: 56vw; padding: 9px 11px; }
  #goalList li { font-size: 12px; }
  #clock { font-size: 30px; }
  #mapWrap, #minimap { width: 120px; height: 120px; }
  #stats { width: 190px; bottom: auto; top: auto; left: 12px; bottom: 12px; padding: 9px 11px; }
  #prompt { bottom: 300px; font-size: 14px; }
  .report { grid-template-columns: repeat(2, 1fr); }
  .quiz-a { grid-template-columns: 1fr; }
  #create.screen.side { padding: 12px; justify-content: center; align-items: flex-end; }
  #create .panel { max-height: 62vh; }
}
