:root {
  --ink: #f2e6cf; --ink2: #cdb894; --leather: #3a2618; --leather2: #5a3d27; --brass: #e0b25e; --bad: #ff7a6a; --ok: #9ff59a;
  --safe-b: env(safe-area-inset-bottom, 0px); --safe-t: env(safe-area-inset-top, 0px);
  font-family: "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", "Yu Gothic", Meiryo, sans-serif;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #0e0a07; color: var(--ink); overscroll-behavior: none; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#app { position: fixed; inset: 0; overflow: hidden; touch-action: none; }
#app.hurtflash::after { content: ''; position: absolute; inset: 0; background: rgba(255, 60, 40, 0.22); pointer-events: none; }
canvas { position: absolute; left: 0; top: 0; display: block; }
#bg, #under, #gl { pointer-events: none; }
#fx { touch-action: none; cursor: crosshair; }
.hidden { display: none !important; }
button { font: inherit; color: var(--ink); background: linear-gradient(#5d412b, #3f2b1c); border: 1px solid #7a5a3c; border-radius: 12px; padding: 10px 14px; box-shadow: 0 2px 0 #1d130b, inset 0 1px 0 rgba(255, 255, 255, 0.12); cursor: pointer; touch-action: manipulation; }
button:active { transform: translateY(1px); box-shadow: 0 1px 0 #1d130b; }
button:disabled { opacity: 0.45; }
button.big { font-size: 18px; font-weight: 700; padding: 14px 18px; background: linear-gradient(#c68f3c, #8a5a20); border-color: #e7b866; color: #fff8e8; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.4); }

/* HUD */
#hud { position: absolute; left: 0; right: 0; top: 0; padding: calc(6px + var(--safe-t)) 8px 0; pointer-events: none; z-index: 5; }
#hud .row1 { display: flex; align-items: center; gap: 8px; }
#hud button, #hud .head { pointer-events: auto; }
#btnMenu { width: 40px; height: 40px; padding: 0; font-size: 20px; }
#horseInfo { flex: 1; min-width: 0; line-height: 1.15; text-shadow: 0 1px 2px #000; }
#horseInfo b { display: block; font-size: 16px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#horseInfo span { font-size: 12px; color: var(--ink2); }
#hearts { font-size: 18px; letter-spacing: 1px; }
#hearts .on { color: #ff6a5a; text-shadow: 0 0 6px rgba(255, 80, 60, 0.6); }
#hearts .off { color: #4a3a32; }
#timer { font-variant-numeric: tabular-nums; font-size: 15px; background: rgba(0, 0, 0, 0.35); padding: 4px 8px; border-radius: 8px; }
#hud .row2 { margin-top: 4px; }
#legs { display: flex; gap: 4px; font-size: 11px; }
#legs span { padding: 2px 6px; border-radius: 6px; background: rgba(0, 0, 0, 0.35); color: #8d7b62; }
#legs span.cur { background: var(--brass); color: #2a1a0c; font-weight: 700; }
#legs span.done { color: var(--ok); }
#tasks { display: flex; gap: 4px; margin-top: 5px; }
.task { flex: 1; background: rgba(0, 0, 0, 0.42); border-radius: 7px; padding: 3px 5px 4px; font-size: 10px; min-width: 0; }
.task b { display: block; font-weight: 600; color: var(--ink2); white-space: nowrap; }
.task i { display: block; height: 4px; background: rgba(255, 255, 255, 0.12); border-radius: 2px; margin-top: 2px; overflow: hidden; }
.task u { display: block; height: 100%; background: #d9a74c; text-decoration: none; transition: width 0.3s; }
.task.ok b { color: var(--ok); }
.task.ok u { background: #7fdc6a; }
#lobes { display: flex; gap: 6px; margin-top: 5px; justify-content: center; }
.head { background: rgba(0, 0, 0, 0.45); border-radius: 8px; padding: 2px 6px; font-size: 11px; display: flex; align-items: center; gap: 4px; }
.head i { width: 40px; height: 4px; background: rgba(255, 255, 255, 0.15); border-radius: 2px; overflow: hidden; display: block; }
.head u { display: block; height: 100%; background: #ff8a5a; }
.head.angry { animation: shake 0.2s infinite; }
@keyframes shake { 50% { transform: translateX(2px); } }

/* 道具バー（親指で届く下端） */
#toolbar { position: absolute; left: 0; right: 0; bottom: 0; padding: 6px 6px calc(8px + var(--safe-b)); display: flex; gap: 5px; justify-content: center; z-index: 6; background: linear-gradient(rgba(14, 10, 7, 0), rgba(14, 10, 7, 0.85) 30%); }
.tool { position: relative; flex: 1; max-width: 86px; min-width: 0; height: 78px; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 4px 2px; gap: 2px; font-size: 12px; border-radius: 14px; }
.tool canvas { position: static; }
.tool i { position: absolute; top: 3px; right: 6px; font-size: 9px; font-style: normal; color: #9a8466; }
.tool.active { background: linear-gradient(#d39c46, #8f5c1f); border-color: #ffd48a; box-shadow: 0 0 12px rgba(255, 190, 90, 0.5); color: #fff; }
#sideBtn, #finishBtn { position: absolute; z-index: 6; bottom: calc(96px + var(--safe-b)); font-size: 13px; padding: 8px 12px; }
#sideBtn { left: 10px; }
#finishBtn { right: 10px; background: linear-gradient(#4c6b39, #2f4724); border-color: #7fa860; }
#finishBtn.pulse { animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 18px rgba(160, 255, 120, 0.8); } }

#hint { position: absolute; left: 50%; top: calc(118px + var(--safe-t)); transform: translateX(-50%); width: max-content; max-width: 92vw; background: rgba(20, 13, 8, 0.82); border: 1px solid rgba(224, 178, 94, 0.5); padding: 7px 12px; border-radius: 10px; font-size: 13px; max-width: 92%; text-align: center; opacity: 0; transition: opacity 0.3s; pointer-events: none; z-index: 7; }
#hint.show { opacity: 1; }
#toast { position: absolute; left: 50%; top: 42%; transform: translate(-50%, -50%) scale(0.9); padding: 10px 16px; border-radius: 12px; background: rgba(20, 13, 8, 0.9); font-weight: 700; opacity: 0; transition: 0.2s; pointer-events: none; z-index: 8; white-space: nowrap; }
#toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
#toast.bad { background: rgba(120, 20, 14, 0.92); }
#toast.warn { background: rgba(110, 70, 10, 0.92); }
#suggest { position: absolute; left: 50%; bottom: calc(140px + var(--safe-b)); transform: translateX(-50%) translateY(20px); background: rgba(40, 70, 30, 0.95); border: 1px solid #8fd06a; padding: 9px 14px; border-radius: 12px; font-size: 14px; opacity: 0; pointer-events: none; transition: 0.3s; z-index: 7; white-space: nowrap; }
#suggest.show { opacity: 1; transform: translateX(-50%); pointer-events: auto; }
.float { position: absolute; transform: translate(-50%, -50%); font-weight: 800; font-size: 16px; text-shadow: 0 2px 3px #000; pointer-events: none; animation: floatup 1.1s ease-out forwards; z-index: 9; white-space: nowrap; }
@keyframes floatup { to { transform: translate(-50%, -150%); opacity: 0; } }

#tutor { position: absolute; left: 50%; top: 52%; transform: translate(-50%, -50%); text-align: center; pointer-events: none; opacity: 0; transition: opacity 0.4s; z-index: 7; }
#tutor.show { opacity: 1; }
#tutor p { background: rgba(20, 13, 8, 0.85); padding: 8px 14px; border-radius: 10px; margin: 70px 0 4px; font-size: 16px; }
#tutor small { background: rgba(20, 13, 8, 0.7); padding: 4px 10px; border-radius: 8px; font-size: 11px; color: var(--ink2); }
#tutor .finger { position: absolute; left: 50%; top: 0; width: 44px; height: 44px; margin-left: -22px; border-radius: 50%; background: rgba(255, 245, 225, 0.85); box-shadow: 0 0 0 6px rgba(255, 245, 225, 0.25); animation: swipe 1.4s ease-in-out infinite; }
@keyframes swipe { 0% { transform: translate(-60px, -10px); opacity: 0; } 15% { opacity: 1; } 70% { transform: translate(60px, 10px); opacity: 1; } 100% { transform: translate(60px, 10px); opacity: 0; } }

/* 画面 */
.screen { position: absolute; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: calc(16px + var(--safe-t)) 14px calc(16px + var(--safe-b)); }
.scroll { overflow-y: auto; justify-content: flex-start; touch-action: pan-y; -webkit-overflow-scrolling: touch; }
.card-screen { background: rgba(8, 5, 3, 0.5); }
.card { width: min(380px, 100%); background: linear-gradient(#2e2015, #1e150d); border: 1px solid #6b4c30; border-radius: 18px; padding: 16px; box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6); display: flex; flex-direction: column; gap: 10px; }
.card.wide { width: min(440px, 100%); margin: auto 0; }
.card h2 { margin: 0; font-size: 20px; }
.card .tag { margin: 0; font-size: 12px; color: var(--brass); letter-spacing: 0.2em; }
.card .sp { margin: 0; color: var(--ink2); font-size: 13px; }
.feat { margin: 0; padding: 0; list-style: none; display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.feat li { background: rgba(0, 0, 0, 0.3); border-radius: 8px; padding: 5px 8px; font-size: 12px; }
.feat b { display: block; font-size: 10px; color: var(--ink2); font-weight: 500; }
.desc { margin: 0; font-size: 13px; line-height: 1.5; color: #f4d8a8; }
.goal { margin: 0; font-size: 12px; line-height: 1.5; color: #9fd6ea; }
.small { margin: 0; font-size: 11px; color: var(--ink2); text-align: center; line-height: 1.5; }
.meta { margin: 0; font-size: 13px; color: var(--ink2); text-align: center; line-height: 1.6; }
.row { display: flex; gap: 8px; }
.row button { flex: 1; }
.score { display: flex; align-items: baseline; justify-content: center; gap: 12px; }
.score span { font-size: 40px; font-weight: 800; }
.score small { font-size: 14px; margin-left: 2px; }
.rank { font-size: 44px; font-weight: 900; font-style: italic; }
.rS { color: #ffe39a; text-shadow: 0 0 14px rgba(255, 210, 100, 0.8); }
.rA { color: #b8f59a; } .rB { color: #9fd6ea; } .rC { color: #d9c6a6; } .rD { color: #ff9b8a; }
.ba2 { display: flex; gap: 8px; }
.baimg { flex: 1; position: relative; background: #120c08; border-radius: 10px; overflow: hidden; }
.baimg canvas { position: static; width: 100%; height: auto; display: block; }
.baimg em { position: absolute; left: 6px; top: 4px; font-size: 10px; font-style: normal; font-weight: 700; background: rgba(0, 0, 0, 0.5); padding: 1px 5px; border-radius: 4px; }
.break { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 3px; }
.break li { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.break span { width: 96px; color: var(--ink2); }
.break i { flex: 1; height: 6px; background: rgba(255, 255, 255, 0.1); border-radius: 3px; overflow: hidden; }
.break u { display: block; height: 100%; background: #d9a74c; }
.break b { width: 24px; text-align: right; }
#baCanvas { position: static; width: 100%; height: auto; border-radius: 12px; touch-action: none; background: #120c08; }
.rhead { display: flex; align-items: center; gap: 10px; }
.rhead canvas { position: static; width: 100px; height: 80px; }
.rhead > div { flex: 1; }
.thumbs { display: flex; gap: 6px; }
.thumb { flex: 1; padding: 3px; display: flex; flex-direction: column; align-items: center; font-size: 11px; gap: 2px; }
.thumb canvas { position: static; width: 100%; height: auto; border-radius: 6px; }
.thumb.on { border-color: var(--brass); box-shadow: 0 0 10px rgba(224, 178, 94, 0.6); }
.list { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 8px; }
.list li { display: flex; align-items: center; gap: 10px; background: rgba(0, 0, 0, 0.3); border-radius: 10px; padding: 10px; }
.list li > div { flex: 1; }
.list p { margin: 4px 0 0; font-size: 12px; color: var(--ink2); line-height: 1.5; }
.list .lv { font-size: 11px; color: var(--brass); }
.list li.unk { opacity: 0.55; flex-direction: column; align-items: flex-start; }
.list li.titles { flex-direction: column; align-items: flex-start; }

#title { justify-content: space-between; background: linear-gradient(rgba(8, 5, 3, 0.15), rgba(8, 5, 3, 0.15) 50%, rgba(8, 5, 3, 0.85)); }
.logo { text-align: center; margin-top: 4vh; }
.logo h1 { margin: 0; font-size: clamp(34px, 11vw, 60px); letter-spacing: 0.06em; font-weight: 900; color: #f6e2b8; text-shadow: 0 3px 0 #5a3a1c, 0 6px 20px rgba(0, 0, 0, 0.8); }
.logo .sub { margin: 2px 0 0; font-size: 18px; letter-spacing: 0.5em; color: var(--brass); text-shadow: 0 2px 6px #000; }
.menu { width: min(340px, 100%); display: flex; flex-direction: column; gap: 10px; margin-top: auto; }
.menu small { font-size: 11px; opacity: 0.8; }
.status { display: flex; align-items: center; justify-content: center; gap: 14px; margin-top: 12px; font-size: 13px; color: var(--ink2); }
.status button { padding: 6px 10px; }
.credit { font-size: 10px; color: #7d6a52; margin: 6px 0 0; }
#inspect { justify-content: flex-end; background: linear-gradient(rgba(8, 5, 3, 0), rgba(8, 5, 3, 0.55) 55%); }
#inspect .card { gap: 8px; }
.vol { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--ink2); }
.vol label { width: 84px; flex: none; }
.vol input { flex: 1; accent-color: #d9a74c; height: 28px; touch-action: pan-x; }
.task b em { font-style: normal; color: var(--ink); font-weight: 700; margin-left: 2px; }
#toolbar.care .tool { max-width: 120px; }
.menu .big small { display: block; font-size: 11px; font-weight: 500; opacity: 0.85; }
#timer:empty { display: none; }
