:root {
  --purple: #6b2fa0; --purple-d: #2a1346; --purple-dd: #170a2b; --orange: #ff8a1f; --orange-l: #ffc38a; --pink: #ff5fa8; --green: #7dff3a;
  --pad-h: clamp(150px, 27vh, 230px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--purple-dd); color: #fff; font-family: ui-monospace, "Courier New", monospace; overflow: hidden; overscroll-behavior: none; touch-action: none; }
#app { display: flex; flex-direction: column; height: 100%; height: 100dvh; max-width: 1100px; margin: 0 auto; }
#stage { position: relative; flex: 1; min-height: 0; background: #3b3550; border: 3px solid var(--orange); border-bottom: 0; border-radius: 10px 10px 0 0; overflow: hidden; }
#game { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; image-rendering: crisp-edges; display: block; }
#hud { position: absolute; inset: 0; pointer-events: none; }
#hud > * { pointer-events: none; }
#hud button, #hud .btn { pointer-events: auto; }
#hud-top { display: flex; gap: 6px; padding: 6px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.chip { background: rgba(23, 10, 43, .82); border: 2px solid var(--orange); color: #fff; border-radius: 8px; padding: 3px 8px; font: bold 13px ui-monospace, monospace; }
.chip b { color: var(--orange-l); }
button.chip { cursor: pointer; font-size: 18px; padding: 2px 9px; }
#task { position: absolute; left: 6px; top: 46px; width: min(220px, 58%); background: rgba(23, 10, 43, .86); border: 2px solid var(--green); border-radius: 8px; padding: 6px 8px; font-size: 12px; }
#task-title { font-weight: bold; color: var(--orange-l); margin-bottom: 4px; }
.bar { height: 8px; background: #3a2455; border-radius: 4px; overflow: hidden; margin: 2px 0; }
.bar i { display: block; height: 100%; width: 0; background: var(--orange); }
.bar.calm i { background: var(--green); }
.mini { pointer-events: auto; margin-top: 4px; font: bold 11px ui-monospace, monospace; background: var(--purple); color: #fff; border: 2px solid var(--orange); border-radius: 6px; padding: 3px 8px; }
#minimap { position: absolute; right: 6px; top: 46px; width: 118px; height: 72px; border: 2px solid var(--orange); border-radius: 4px; image-rendering: pixelated; background: #170a2b; }
#toast { position: absolute; left: 50%; top: 24%; transform: translateX(-50%); max-width: 90%; text-align: center; background: rgba(23, 10, 43, .9); border: 2px solid var(--orange); color: #fff; padding: 6px 12px; border-radius: 8px; font-size: 13px; opacity: 0; transition: opacity .25s; }
#toast.on { opacity: 1; }
#hint { position: absolute; left: 50%; bottom: 8px; transform: translateX(-50%); background: rgba(23, 10, 43, .85); border: 2px solid var(--green); border-radius: 8px; padding: 3px 10px; font-size: 12px; opacity: 0; transition: opacity .15s; white-space: nowrap; }
#hint.on { opacity: 1; }

/* ---- controller ---- */
#pad { position: relative; }
#btn-pause { position: absolute; top: 6px; right: 8px; width: 30px; height: 26px; display: flex; gap: 5px; align-items: center; justify-content: center; padding: 0; cursor: pointer;
  background: rgba(255, 255, 255, .14); border: 1px solid rgba(255, 255, 255, .35); border-radius: 8px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); box-shadow: inset 0 1px 0 rgba(255, 255, 255, .3); opacity: .6; z-index: 2; }
#btn-pause span { width: 4px; height: 12px; background: rgba(255, 255, 255, .85); border-radius: 1px; }
#btn-pause:hover, #btn-pause:focus-visible { opacity: 1; }
#shot-preview { width: 100%; image-rendering: pixelated; border: 2px solid var(--purple); border-radius: 8px; margin-top: 6px; }
#pad { height: var(--pad-h); flex: none; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; padding: 8px 14px calc(8px + env(safe-area-inset-bottom)); gap: 8px;
  background: linear-gradient(#3a1a66, #24103f); border: 3px solid var(--orange); border-top: 4px solid #b560ff; border-radius: 0 0 22px 22px; user-select: none; -webkit-user-select: none; }
#dpad, #abtns { --s: clamp(44px, calc(var(--pad-h) * .3), 66px); display: grid; grid-template-columns: repeat(3, var(--s)); grid-template-rows: repeat(3, var(--s)); justify-content: center; }
#dpad { justify-self: start; }
#abtns { justify-self: end; }
#dpad button { background: #1a0d2e; color: #d9c2ff; border: 2px solid #0e0619; font-size: calc(var(--s) * .4); border-radius: 6px; box-shadow: inset 0 -4px 0 #05020a, 0 2px 0 #7a4cb0; padding: 0; }
#dpad button[data-b=up] { grid-area: 1/2; border-radius: 10px 10px 4px 4px; }
#dpad button[data-b=left] { grid-area: 2/1; border-radius: 10px 4px 4px 10px; }
#dpad button[data-b=right] { grid-area: 2/3; border-radius: 4px 10px 10px 4px; }
#dpad button[data-b=down] { grid-area: 3/2; border-radius: 4px 4px 10px 10px; }
#dpad i { grid-area: 2/2; background: #1a0d2e; }
#dpad button.on, #abtns button.on { transform: translateY(2px); filter: brightness(1.5); box-shadow: none; }
.b { border-radius: 50%; border: 3px solid rgba(0, 0, 0, .55); font: bold calc(var(--s) * .55)/1 ui-monospace, monospace; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, .4); box-shadow: inset 0 -5px 0 rgba(0, 0, 0, .3), 0 3px 0 #05020a; padding: 0; }
.b.green { background: #2fbf4f; grid-area: 1/2; }
.b.blue { background: #2f6ae0; grid-area: 2/3; }
.b.yellow { background: #e8c020; grid-area: 3/2; color: #3a2a00; text-shadow: none; }
.b.red { background: #e03a3a; grid-area: 2/1; }
#center { text-align: center; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 70px; }
#logo { width: calc(var(--pad-h) * .36); max-width: 72px; image-rendering: pixelated; border-radius: 8px; }
#player-name { font-size: 10px; opacity: .55; max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#btn-labels { font-size: 9px; display: flex; gap: 6px; opacity: .85; }
#btn-labels span:first-child { color: #7dff9a; } #btn-labels span:last-child { color: #7fb0ff; }
@media (max-width: 480px) { #pad { padding: 6px 8px calc(6px + env(safe-area-inset-bottom)); } #center { min-width: 56px; } }

/* ---- modals ---- */
#modal { position: fixed; inset: 0; background: rgba(10, 4, 20, .78); display: flex; align-items: center; justify-content: center; z-index: 10; padding: 10px; touch-action: pan-y; }
#modal[hidden] { display: none; }
#modal-card { background: #24103f; border: 3px solid var(--orange); border-radius: 14px; width: min(560px, 100%); max-height: 94vh; max-height: 94dvh; overflow: auto; padding: 14px 16px; box-shadow: 0 0 0 4px var(--purple); }
#modal-card h2 { margin: 0 0 8px; color: var(--orange-l); font-size: 18px; }
#modal-card h3 { margin: 14px 0 6px; color: #d9a8ff; font-size: 14px; border-bottom: 1px solid #5a3a85; padding-bottom: 3px; }
#modal-card p { line-height: 1.45; font-size: 14px; margin: 6px 0; }
#modal-card a { color: var(--orange); }
#modal-card input[type=text], #modal-card input[type=password] { width: 100%; padding: 9px; font: 16px ui-monospace, monospace; background: #170a2b; color: #fff; border: 2px solid var(--purple); border-radius: 8px; margin: 4px 0; }
#modal-card input:focus { outline: none; border-color: var(--orange); }
.row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; align-items: center; }
.row.end { justify-content: flex-end; }
.row.legal-row { justify-content: space-between; }
.legal { font-size: 12px; opacity: .85; }
.legal a { color: inherit; }
.btnx { font: bold 14px ui-monospace, monospace; padding: 9px 14px; border-radius: 8px; border: 2px solid var(--orange); background: var(--purple); color: #fff; cursor: pointer; touch-action: manipulation; }
.btnx.primary { background: var(--orange); color: #2a1346; }
.btnx.danger { background: #b02a2a; border-color: #ff7a7a; }
.btnx:disabled { opacity: .4; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.chips .btnx { font-size: 12px; padding: 6px 9px; }
.stat { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px dashed #4a2d70; font-size: 14px; }
.stat b { color: var(--orange-l); }
.reply { background: #170a2b; border-left: 4px solid var(--orange); padding: 8px 10px; border-radius: 4px; margin: 8px 0; font-size: 14px; line-height: 1.4; }
.reply small { display: block; color: #d9a8ff; margin-bottom: 3px; }
.msg-you { text-align: right; color: #a9ffc0; font-size: 13px; margin: 6px 0; }
.err { color: #ff8a8a; font-size: 13px; min-height: 16px; }
.ok { color: #8aff9a; }
.hatgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(110px, 1fr)); gap: 8px; }
.hatgrid canvas { width: 64px; height: 48px; image-rendering: pixelated; background: #3b3550; border-radius: 6px; display: block; margin: 0 auto 4px; }
.hatcard { background: #170a2b; border: 2px solid #4a2d70; border-radius: 8px; padding: 6px; text-align: center; font-size: 12px; }
.hatcard.sel { border-color: var(--green); }
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px; }
.gallery img { width: 100%; height: 120px; object-fit: cover; border-radius: 6px; border: 2px solid var(--purple); }
.credit { margin-top: 14px; font-size: 12px; opacity: .85; text-align: center; }
.hamlet { white-space: pre-wrap; font-size: 13px; line-height: 1.5; background: #f4ecd8; color: #2b1d12; padding: 10px; border-radius: 6px; font-family: Georgia, serif; }
.logo-row { display: flex; align-items: center; gap: 10px; }
.logo-row img { width: 48px; image-rendering: pixelated; }
.tabs { display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 8px; }
.tabs .btnx { padding: 6px 10px; font-size: 12px; }
.tabs .btnx.cur { background: var(--orange); color: #2a1346; }

/* ---- print ---- */
#print-sheet { display: none; }
@page { margin: 12mm; }
@media print {
  * { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body > *:not(#print-sheet) { display: none !important; }
  html, body { overflow: visible; height: auto; background: #fff; color: #000; }
  #print-sheet { display: block !important; font-family: Georgia, serif; padding: 30px; color: #000; }
  #print-sheet header { text-align: center; border-bottom: 4px solid #6b2fa0; padding-bottom: 12px; }
  #print-sheet header img { width: 110px; height: 110px; image-rendering: pixelated; border-radius: 14px; }
  #print-sheet h1 { margin: 6px 0 0; color: #6b2fa0; font-size: 34px; }
  #print-sheet .sub { margin-top: 2px; font-size: 12px; color: #555; }
  #print-sheet h2 { text-align: center; margin: 18px 0; }
  #print-sheet table { margin: 0 auto; width: 70%; border-collapse: collapse; font-size: 18px; }
  #print-sheet td { border-bottom: 1px solid #ccc; padding: 8px 4px; } #print-sheet td:last-child { text-align: right; font-weight: bold; color: #c25a00; }
  #print-sheet .shot { width: 100%; image-rendering: pixelated; }
  #print-sheet .meta { text-align: center; color: #555; font-size: 13px; }
  #print-sheet .chat { max-width: 600px; margin: 0 auto; font-size: 16px; line-height: 1.5; }
  #print-sheet .chat .you { color: #6b2fa0; }
  #print-sheet footer { position: fixed; bottom: 20px; left: 0; right: 0; text-align: center; font-size: 13px; border-top: 2px solid #ff8a1f; padding-top: 8px; }
}
