:root {
  --bg: #1f3d2a; --panel: #f4ecd6; --ink: #2a2118; --accent: #ffcf3d; --hot: #e8483f;
  --font: 'DotGothic16', 'Hiragino Kaku Gothic ProN', 'Noto Sans JP', monospace;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--panel); font-family: var(--font); overflow: hidden; overscroll-behavior: none; }
button { font-family: var(--font); font-size: 15px; color: var(--ink); background: var(--panel); border: 0; border-radius: 0;
  box-shadow: inset -3px -3px 0 rgba(0,0,0,.25), 0 0 0 2px var(--ink); padding: 8px 10px; cursor: pointer; touch-action: manipulation; }
button:active { box-shadow: inset 3px 3px 0 rgba(0,0,0,.25), 0 0 0 2px var(--ink); }
[hidden] { display: none !important; }

#editor { display: flex; flex-direction: column; height: 100%; padding: max(8px, env(safe-area-inset-top)) 10px max(10px, env(safe-area-inset-bottom)); gap: 8px; }
header { display: flex; align-items: center; gap: 10px; }
h1 { font-size: 22px; margin: 0; letter-spacing: 2px; color: var(--accent); text-shadow: 2px 2px 0 #000; }
#best { flex: 1; font-size: 14px; opacity: .9; text-align: right; }
#work { flex: 1; display: flex; gap: 10px; min-height: 0; justify-content: center; }
#gridWrap { display: flex; align-items: flex-start; justify-content: center; min-width: 0; }
#grid { touch-action: none; display: block; box-shadow: 0 0 0 3px var(--ink), 6px 6px 0 rgba(0,0,0,.35); }
#side { display: flex; flex-direction: column; gap: 8px; width: 96px; flex: none; }
#palette { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
#palette button { aspect-ratio: 1; padding: 0; font-size: 16px; color: var(--ink); box-shadow: inset -3px -3px 0 rgba(0,0,0,.2), 0 0 0 2px var(--ink); }
#palette button.on { transform: translate(-2px, -2px); box-shadow: inset -3px -3px 0 rgba(0,0,0,.2), 0 0 0 2px var(--ink), 0 0 0 4px #fff, 4px 4px 0 4px #000; }
#tools { display: grid; gap: 6px; margin-top: 4px; }
#tools button { font-size: 13px; padding: 6px; }
#stats { font-size: 13px; line-height: 1.5; margin-top: auto; }
#stats b { font-size: 17px; color: var(--accent); display: block; }
#stats .warn { color: #ffb4a8; font-size: 12px; }
#bottom { display: flex; gap: 10px; }
#name { flex: 1; min-width: 0; font-family: var(--font); font-size: 16px; padding: 8px; border: 0; background: #11241a; color: var(--panel); box-shadow: 0 0 0 2px var(--ink) inset; }
#btnShot { font-size: 22px; padding: 10px 26px; background: var(--hot); color: #fff; }

#shot { position: fixed; inset: 0; }
#scene { display: block; width: 100%; height: 100%; }
#hud { position: absolute; top: max(14px, env(safe-area-inset-top)); left: 0; right: 0; text-align: center; font-size: 34px; color: #fff; text-shadow: 3px 3px 0 #000; pointer-events: none; }
#hud small { display: block; font-size: 14px; }
#btnSkip { position: absolute; right: 12px; bottom: max(14px, env(safe-area-inset-bottom)); font-size: 20px; padding: 6px 14px; }
#result { position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(94vw, 400px); max-height: 96vh; overflow: auto; background: var(--panel); color: var(--ink);
  box-shadow: 0 0 0 3px var(--ink), 8px 8px 0 rgba(0,0,0,.4); padding: 14px 16px 16px; }
#result .hero { display: flex; gap: 14px; align-items: flex-start; }
#result .side { flex: 1; min-width: 0; display: flex; flex-direction: column; align-items: flex-start; gap: 4px; }
#result .msg { font-size: 16px; color: var(--hot); }
#result .cname { font-size: 19px; line-height: 1.25; word-break: break-all; margin-left: -6px; }
#result .dist { font-size: 40px; line-height: 1; }
#result .dist small { font-size: 18px; }
#result canvas { flex: none; box-shadow: 0 0 0 3px var(--ink); background: #e8dfc4; }
#result .badge { display: inline-block; background: var(--accent); padding: 0 6px; font-size: 15px; box-shadow: 0 0 0 2px var(--ink); }
#result .tag { display: block; background: #fff3c4; box-shadow: 0 0 0 2px var(--ink); padding: 2px 6px; font-size: 14px; margin-top: 4px; }
#result .tag small { display: block; font-size: 11px; opacity: .75; }
#result .ev { margin-top: 10px; padding: 4px 8px; background: #e3f1ff; box-shadow: 0 0 0 2px var(--ink); font-size: 12px; }
#result i { font-style: normal; background: var(--hot); color: #fff; font-size: 11px; padding: 0 4px; margin-right: 6px; }
#result .stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px 14px; margin: 10px 0 0; font-size: 12px; }
#result .stats div { display: flex; justify-content: space-between; gap: 4px; }
#result .stats dt { opacity: .65; } #result .stats dd { margin: 0; }
#result .btns { display: flex; gap: 10px; margin-top: 12px; }
#result .btns .share { background: #111; color: #fff; font-size: 17px; }
#result .btns .rank { background: var(--accent); font-size: 16px; }
#result .rankmsg { font-size: 13px; margin-top: 6px; min-height: 0; }
#result .rankmsg:empty { display: none; }
#result .rankmsg b { color: var(--hot); font-weight: normal; font-size: 16px; }
#result .btns button { flex: 1; }
#result .btns .main { background: var(--hot); color: #fff; }

#modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; z-index: 10; }
#modal .box { background: var(--panel); color: var(--ink); width: min(92vw, 400px); max-height: 82vh; overflow: auto; padding: 14px; box-shadow: 0 0 0 3px var(--ink); }
#modal h2 { margin: 0 0 8px; font-size: 20px; }
#modal ol { list-style: none; margin: 0; padding: 0; }
#modal li { display: flex; align-items: center; gap: 10px; padding: 6px 4px; border-bottom: 2px dashed rgba(0,0,0,.15); cursor: pointer; }
#modal li:active { background: rgba(0,0,0,.08); }
#modal li .rk { width: 2em; text-align: right; font-size: 18px; }
#modal li .d { font-size: 20px; flex: 1; }
#modal li .d small { display: block; font-size: 12px; opacity: .7; }
#modal li canvas { image-rendering: pixelated; box-shadow: 0 0 0 1px var(--ink); background: #e8dfc4; }
#modal .close { width: 100%; margin-top: 12px; }
#modal p { font-size: 14px; }

#stats .on { display: block; color: #ffcf3d; font-size: 12px; margin-top: 4px; }
#stats .on::before { content: '発動中'; display: block; color: var(--panel); opacity: .7; }
.zukan i { font-style: normal; background: var(--hot); color: #fff; font-size: 11px; padding: 0 4px; }
.zukan h2 small { font-size: 14px; opacity: .7; }
.zukan h3 { font-size: 15px; margin: 12px 0 4px; border-bottom: 2px solid var(--ink); }
.zukan ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
#modal .zukan li { display: block; cursor: default; border: 0; padding: 6px 8px; box-shadow: 0 0 0 2px var(--ink); font-size: 13px; }
#modal .zukan li b { display: block; font-size: 16px; font-weight: normal; }
#modal .zukan li em { display: block; font-style: normal; color: var(--hot); }
#modal .zukan li.nope { background: rgba(0,0,0,.1); color: rgba(0,0,0,.45); }

#modal .rank .tabs { display: flex; gap: 8px; margin-bottom: 10px; }
#modal .rank .tabs button { flex: 1; padding: 6px; font-size: 14px; }
#modal .rank .tabs button.on { background: var(--accent); }
#modal .rank .list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
#modal .rank .list p { grid-column: 1 / -1; }
#modal .rank .club { position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 6px 4px; cursor: pointer; box-shadow: 0 0 0 2px var(--ink); background: #fffaf0; }
#modal .rank .club:active { background: #f1e6c8; }
#modal .rank .club.me { background: #fff3c4; }
#modal .rank .club canvas { width: 100%; max-width: 42px; height: auto; box-shadow: 0 0 0 1px var(--ink); }
#modal .rank .club .rk { position: absolute; top: 2px; left: 4px; font-size: 15px; color: var(--hot); }
#modal .rank .club .nm { font-size: 12px; line-height: 1.2; text-align: center; word-break: break-all; }
#modal .rank .club .d { font-size: 13px; }
#modal .rank .hint { font-size: 12px; opacity: .7; margin: 8px 0 0; }
