:root {
  --wood1: #9a6232; --wood2: #6b3f1d; --wood3: #4a2a12; --gold: #f0c068; --gold2: #b7832f;
  --parch: #f6e7c4; --ink: #3a2414; --font: ui-rounded, "SF Pro Rounded", "Nunito", "Trebuchet MS", system-ui, sans-serif;
  --st: env(safe-area-inset-top, 0px); --sb: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: radial-gradient(ellipse at 50% 40%, #2a3146 0%, #151925 75%); font-family: var(--font); user-select: none; -webkit-user-select: none; touch-action: none; }
#c { position: fixed; inset: 0; width: 100vw; height: 100vh; display: block; touch-action: none; }
#ui { position: fixed; inset: 0; pointer-events: none; }
#ui > * { pointer-events: auto; }
.hidden { display: none !important; }
button { font-family: var(--font); }

/* ---- top left: portrait + bars ---- */
#topleft { position: absolute; left: 8px; top: calc(8px + var(--st)); display: flex; gap: 6px; pointer-events: none; }
#portrait { width: 70px; height: 70px; border-radius: 14px; border: 3px solid var(--gold); background: transparent; box-shadow: 0 0 0 3px var(--wood3), 0 4px 10px rgba(0,0,0,.5), inset 0 0 12px rgba(0,0,0,.6); position: relative; }
#lv { position: absolute; left: 50%; bottom: -12px; transform: translateX(-50%); background: linear-gradient(var(--wood1), var(--wood2)); color: #fff4d8; font-weight: 900; font-size: 12px; padding: 2px 8px; border-radius: 9px; border: 2px solid var(--gold); white-space: nowrap; text-shadow: 0 1px 0 #000; }
#bars { display: flex; flex-direction: column; gap: 4px; padding-top: 3px; }
.bar { display: flex; align-items: center; }
.bar .ico { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; color: #fff; border: 2px solid var(--gold); box-shadow: 0 0 0 2px var(--wood3); z-index: 1; font-style: normal; }
.hp .ico { background: radial-gradient(#ff7b6b, #b3261e); }
.mp .ico { background: radial-gradient(#7fd0ff, #1f5fae); }
.en .ico { background: radial-gradient(#e8f36a, #7a8f1a); color: #3a3a00; }
.track { width: 118px; height: 13px; margin-left: -5px; border-radius: 0 8px 8px 0; background: #1b1410; border: 2px solid var(--wood2); box-shadow: inset 0 2px 3px rgba(0,0,0,.6); overflow: hidden; }
.fill { height: 100%; width: 100%; border-radius: 0 6px 6px 0; transition: width .4s; }
.hp .fill { background: linear-gradient(#ff8a7a, #d9372a 60%, #a8251b); }
.mp .fill { background: linear-gradient(#9be0ff, #3b8fe0 60%, #2364b0); }
.en .fill { background: linear-gradient(#fff38a, #f0c419 60%, #c49708); }
#xp { margin-left: 22px; width: 96px; height: 5px; background: rgba(0,0,0,.5); border-radius: 3px; overflow: hidden; }
#xpfill { height: 100%; width: 0; background: linear-gradient(90deg, #c9a2ff, #ffffff); transition: width .5s; }

/* ---- top right ---- */
#topright { position: absolute; right: 8px; top: calc(8px + var(--st)); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
#topright > * { pointer-events: auto; }
#mapwrap { position: relative; width: 96px; height: 96px; border-radius: 50%; border: 4px solid var(--gold); box-shadow: 0 0 0 4px var(--wood2), 0 0 0 6px var(--wood3), 0 6px 12px rgba(0,0,0,.5); overflow: hidden; background: #e9d6a6; }
#minimap { width: 100%; height: 100%; display: block; }
.north { position: absolute; top: -2px; left: 50%; transform: translateX(-50%); font-size: 10px; font-weight: 900; color: #fff; background: #b3261e; border-radius: 6px; padding: 0 4px; border: 1px solid var(--gold); }
.round { width: 44px; height: 44px; border-radius: 50%; border: 3px solid var(--gold); background: radial-gradient(circle at 40% 35%, #c58a4f, var(--wood2)); box-shadow: 0 0 0 3px var(--wood3), 0 4px 8px rgba(0,0,0,.5); color: #fff6dc; font-size: 21px; display: grid; place-items: center; padding: 0; cursor: pointer; }
.round:active { transform: scale(.92); }
#btn-hint.on { box-shadow: 0 0 0 3px var(--wood3), 0 0 16px 4px rgba(255,215,90,.8); }

/* ---- sentence line ---- */
#sentence { position: absolute; left: 50%; top: calc(96px + var(--st)); transform: translateX(-50%); background: rgba(30,20,12,.85); color: #ffe7b0; border: 2px solid var(--gold2); border-radius: 14px; padding: 6px 14px; font-weight: 800; font-size: 14px; white-space: nowrap; pointer-events: none; }

/* ---- hint markers ---- */
#hints { position: absolute; inset: 0; pointer-events: none; }
.hint { position: absolute; width: 30px; height: 30px; margin: -15px 0 0 -15px; border-radius: 50%; border: 3px solid #ffe08a; box-shadow: 0 0 12px #ffd24a, inset 0 0 8px #ffd24a; animation: pulse 1.1s ease-in-out infinite; }
.hint::after { content: ''; position: absolute; left: 50%; top: 50%; width: 8px; height: 8px; margin: -4px; border-radius: 50%; background: #fff6c8; }
.hint.done { border-color: rgba(255,255,255,.55); box-shadow: 0 0 8px rgba(255,255,255,.4); }
@keyframes pulse { 0%,100% { transform: scale(.85); opacity: .85; } 50% { transform: scale(1.1); opacity: 1; } }
#hover { position: absolute; padding: 3px 10px; background: rgba(30,20,12,.85); color: #ffe7b0; border-radius: 10px; font-weight: 800; font-size: 13px; pointer-events: none; transform: translate(-50%, -140%); white-space: nowrap; }

/* ---- verb coin ---- */
#verbcoin { position: absolute; transform: translate(-50%, -100%); display: flex; flex-direction: column; align-items: center; gap: 4px; animation: pop .18s ease-out; pointer-events: none; }
#verbcoin > * { pointer-events: auto; }
.vc-name { background: linear-gradient(var(--wood1), var(--wood2)); color: #fff2cf; font-weight: 900; font-size: 14px; padding: 3px 12px; border-radius: 10px; border: 2px solid var(--gold); text-shadow: 0 1px 0 #000; white-space: nowrap; box-shadow: 0 3px 8px rgba(0,0,0,.5); }
.vc-btns { display: flex; gap: 6px; }
.vc-btn { width: 58px; height: 58px; border-radius: 50%; border: 3px solid var(--gold); background: radial-gradient(circle at 40% 35%, #fff4d6, #e3c68a); box-shadow: 0 0 0 3px var(--wood2), 0 5px 10px rgba(0,0,0,.5); display: flex; flex-direction: column; align-items: center; justify-content: center; font-size: 22px; line-height: 1; cursor: pointer; padding: 0; color: var(--ink); }
.vc-btn span { font-size: 10px; font-weight: 900; margin-top: 2px; }
.vc-btn.def { background: radial-gradient(circle at 40% 35%, #fffbe8, #ffd970); }
.vc-btn:active { transform: scale(.9); }
@keyframes pop { from { transform: translate(-50%, -100%) scale(.6); opacity: 0; } to { transform: translate(-50%, -100%) scale(1); opacity: 1; } }

/* ---- dialog ---- */
#dialog { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(86px + var(--sb)); width: min(94vw, 560px); min-height: 74px; background: linear-gradient(#fbf0d4, #efd9a8); border: 3px solid var(--wood2); outline: 2px solid var(--gold); border-radius: 14px; padding: 18px 16px 12px; box-shadow: 0 8px 20px rgba(0,0,0,.55); color: var(--ink); font-weight: 700; font-size: 16px; line-height: 1.35; cursor: pointer; }
#dialog.large { font-size: 20px; }
.dl-name { position: absolute; top: -14px; left: 14px; background: linear-gradient(var(--wood1), var(--wood2)); color: #fff2cf; border: 2px solid var(--gold); border-radius: 9px; font-weight: 900; font-size: 13px; padding: 2px 10px; }
.dl-more { position: absolute; right: 10px; bottom: 4px; font-size: 12px; color: var(--wood2); animation: bob .8s ease-in-out infinite; }
@keyframes bob { 50% { transform: translateY(3px); } }

/* ---- inventory ---- */
#inventory { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(10px + var(--sb)); display: flex; gap: 6px; padding: 7px 9px; background: linear-gradient(#8a5528, #5c3518); border: 3px solid var(--gold2); border-radius: 16px; box-shadow: 0 0 0 3px var(--wood3), 0 6px 14px rgba(0,0,0,.55); }
.slot { width: 52px; height: 52px; border-radius: 10px; background: radial-gradient(#3a2a1e, #22170f); border: 2px solid #b98a45; box-shadow: inset 0 3px 6px rgba(0,0,0,.7); display: grid; place-items: center; font-size: 28px; position: relative; cursor: pointer; padding: 0; }
.slot.sel { border-color: #fff2a8; box-shadow: 0 0 12px 3px rgba(255,220,100,.8), inset 0 3px 6px rgba(0,0,0,.4); background: radial-gradient(#6b5530, #3b2a17); }
.slot .n { position: absolute; right: 3px; bottom: 1px; font-size: 11px; font-weight: 900; color: #ffe7a0; text-shadow: 0 1px 0 #000; }
.slot.new { animation: newitem .9s ease-out; }
@keyframes newitem { 0% { transform: scale(1.6); box-shadow: 0 0 30px 10px #ffe58a; } 100% { transform: scale(1); } }

/* ---- joystick + act button ---- */
#joy { position: absolute; left: 14px; bottom: calc(84px + var(--sb)); width: 128px; height: 128px; border-radius: 50%; background: radial-gradient(circle, #a8713c 0 45%, #7a4a22 46% 70%, #5a3416 71%); border: 4px solid var(--gold2); box-shadow: 0 0 0 4px var(--wood3), 0 8px 14px rgba(0,0,0,.5); touch-action: none; }
#joy .arrow { position: absolute; color: #f6dfb0; font-size: 16px; text-shadow: 0 1px 0 #3a2010; pointer-events: none; }
#joy .up { top: 6px; left: 50%; transform: translateX(-50%); } #joy .down { bottom: 6px; left: 50%; transform: translateX(-50%); }
#joy .left { left: 8px; top: 50%; transform: translateY(-50%); } #joy .right { right: 8px; top: 50%; transform: translateY(-50%); }
#joyknob { position: absolute; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px; border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffffff, #b9bec7 45%, #6d727c); box-shadow: 0 4px 8px rgba(0,0,0,.5); pointer-events: none; }
#btn-act { position: absolute; right: 16px; bottom: calc(92px + var(--sb)); width: 92px; height: 92px; border-radius: 50%; font-size: 40px; border: 4px solid var(--gold); background: radial-gradient(circle at 40% 35%, #d9a064, #7a4a22); box-shadow: 0 0 0 4px var(--wood3), 0 8px 14px rgba(0,0,0,.5); color: #fff; }

/* ---- toast, fade, fps, loader ---- */
#toast { position: absolute; left: 50%; top: 34%; transform: translate(-50%, -50%); pointer-events: none; text-align: center; }
.toastmsg { color: #fff6cf; font-weight: 900; font-size: 26px; text-shadow: 0 3px 0 #6b3f1d, 0 0 18px rgba(255,200,80,.9); animation: rise 2.2s ease-out forwards; white-space: nowrap; }
.toastmsg.small { font-size: 16px; }
@keyframes rise { 0% { transform: translateY(20px) scale(.7); opacity: 0; } 15% { transform: translateY(0) scale(1.08); opacity: 1; } 70% { opacity: 1; } 100% { transform: translateY(-40px); opacity: 0; } }
#fade { position: absolute; inset: 0; background: #070a14; opacity: 0; pointer-events: none; transition: opacity 1s; }
#fps { position: absolute; left: 8px; bottom: calc(80px + var(--sb)); color: #9f9; font: 12px monospace; pointer-events: none; }
#loader { position: absolute; inset: 0; display: grid; place-items: center; background: #151925; color: var(--gold); font-weight: 900; font-size: 18px; transition: opacity .6s; }

/* ---- modals ---- */
.modal { position: absolute; inset: 0; background: rgba(8,10,18,.6); display: grid; place-items: center; }
.panel { width: min(92vw, 440px); max-height: 82vh; display: flex; flex-direction: column; background: linear-gradient(#fbf0d4, #ead29e); border: 4px solid var(--wood2); outline: 3px solid var(--gold); border-radius: 18px; box-shadow: 0 12px 30px rgba(0,0,0,.6); color: var(--ink); overflow: hidden; }
.panel h2 { margin: 0; padding: 10px; text-align: center; background: linear-gradient(var(--wood1), var(--wood2)); color: #fff2cf; font-size: 20px; text-shadow: 0 2px 0 #000; border-bottom: 3px solid var(--gold2); }
.tabs { display: flex; gap: 4px; padding: 8px 8px 0; flex-wrap: wrap; }
.tab { flex: 1; padding: 7px 4px; border: 2px solid var(--wood2); border-bottom: none; border-radius: 10px 10px 0 0; background: #d9bd85; font-weight: 900; color: var(--wood3); font-size: 13px; cursor: pointer; }
.tab.on { background: #fff6dd; }
.body { padding: 12px 14px; overflow-y: auto; background: #fff6dd; margin: 0 8px; border: 2px solid var(--wood2); border-radius: 0 0 10px 10px; flex: 1; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 0; border-bottom: 1px dashed rgba(107,63,29,.3); font-weight: 800; font-size: 15px; }
.row:last-child { border-bottom: none; }
.row input[type=range] { width: 46%; accent-color: #b7832f; }
.choice { display: flex; gap: 3px; flex-wrap: wrap; justify-content: flex-end; }
.choice button { border: 2px solid var(--wood2); background: #ecd7a8; border-radius: 8px; padding: 5px 8px; font-weight: 800; font-size: 12px; color: var(--wood3); cursor: pointer; }
.choice button.on { background: var(--wood1); color: #fff2cf; }
.toggle { width: 52px; height: 28px; border-radius: 14px; border: 2px solid var(--wood2); background: #cdb88e; position: relative; cursor: pointer; padding: 0; }
.toggle::after { content: ''; position: absolute; top: 2px; left: 2px; width: 20px; height: 20px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.4); transition: left .15s; }
.toggle.on { background: #6fa34a; } .toggle.on::after { left: 26px; }
.foot { display: flex; gap: 8px; padding: 10px; justify-content: space-between; align-items: center; }
.foot button { flex: 1; padding: 10px; border-radius: 12px; border: 3px solid var(--wood2); background: #e2c58c; font-weight: 900; font-size: 14px; color: var(--wood3); cursor: pointer; }
.foot button.primary { background: linear-gradient(#ffd56e, #e8a63a); }
.tut-body { padding: 16px 18px; font-weight: 700; font-size: 17px; line-height: 1.45; min-height: 150px; text-align: center; }
.tut-body .big { font-size: 46px; display: block; margin-bottom: 8px; }
.dots { flex: 0 0 auto !important; font-size: 14px; color: var(--wood2); letter-spacing: 3px; }

@media (min-width: 700px) and (orientation: landscape) {
  .track { width: 170px; }
  #portrait { width: 80px; height: 80px; }
}
