/* Ulaki — shell, cabinet, and responsive canvas stage. */
:root {
  --ink: #141018;
  --ink-2: #1e1822;
  --ink-3: #2b2330;
  --panel: #211a28;
  --line: #4a3b4a;
  --cream: #efe2c4;
  --dim: #b9a98f;
  --ember: #e8663d;
  --ember-2: #f3a05b;
  --gold: #e7b65a;
  --moss: #6d8a5c;
  --danger: #c95a5a;
  --ui-font: "Lucida Console", "Cascadia Mono", "Courier New", monospace;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--ink);
  color: var(--cream);
  font-family: var(--ui-font);
  overflow: hidden;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(ellipse at 50% -10%, rgba(232, 102, 61, 0.18), transparent 55%),
    radial-gradient(ellipse at 50% 120%, rgba(70, 96, 80, 0.14), transparent 60%),
    linear-gradient(180deg, #17121b 0%, #100d13 100%);
}

#app {
  height: 100dvh;
  display: flex;
  flex-direction: column;
  padding: max(10px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
           max(8px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  gap: 8px;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 2px;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}

.brand-mark {
  flex: 0 0 10px;
  width: 10px;
  height: 10px;
  align-self: center;
  background: var(--ember);
  box-shadow: 0 0 10px rgba(232, 102, 61, 0.8), 0 0 22px rgba(232, 102, 61, 0.35);
  transform: rotate(45deg);
}

.brand-name {
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--cream);
}

.brand-tag {
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--dim);
  opacity: 0.65;
  white-space: nowrap;
}

.top-actions { display: flex; gap: 8px; }

.icon-btn {
  width: 32px;
  height: 30px;
  border: 1px solid var(--line);
  background: rgba(33, 26, 40, 0.85);
  color: var(--cream);
  font: inherit;
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  border-radius: 2px;
}

.icon-btn:hover, .icon-btn:focus-visible {
  border-color: var(--ember-2);
  color: var(--gold);
  outline: none;
}

.icon-btn.muted { color: var(--danger); opacity: 0.75; }

.bottom-actions {
  flex: 0 0 auto;
  display: flex;
  justify-content: center;
  gap: 9px;
  padding-bottom: 1px;
}

.bottom-btn {
  height: 26px;
  padding: 0 10px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: rgba(33, 26, 40, 0.9);
  color: var(--cream);
  font: inherit;
  font-size: 9px;
  letter-spacing: 0.08em;
  cursor: pointer;
}

.bottom-btn:hover, .bottom-btn:focus-visible {
  border-color: var(--ember-2);
  color: var(--gold);
  outline: none;
}

.bottom-btn kbd { margin-left: 3px; opacity: 0.65; }
.bottom-btn.hud-off { color: var(--dim); opacity: 0.65; }

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#frame {
  position: relative;
  padding: 7px;
  background: linear-gradient(160deg, #3a2e39, #17121c 55%, #0b090e);
  border: 1px solid #4d3c4d;
  border-radius: 6px;
  box-shadow:
    0 0 0 1px #0a080c,
    0 18px 60px rgba(0, 0, 0, 0.75),
    0 0 80px rgba(232, 102, 61, 0.06);
}

#frame::before {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(239, 226, 196, 0.08);
  border-radius: 4px;
  pointer-events: none;
}

#game {
  display: block;
  width: 960px;
  height: 540px;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #100d13;
  border-radius: 2px;
  outline: none;
  cursor: default;
}

#game:focus-visible { box-shadow: 0 0 0 2px var(--ember-2); }

.screen-glass {
  position: absolute;
  inset: 7px;
  pointer-events: none;
  border-radius: 2px;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(0, 0, 0, 0.12) 0px,
      rgba(0, 0, 0, 0.12) 1px,
      transparent 1px,
      transparent 3px
    ),
    radial-gradient(ellipse at center, transparent 58%, rgba(5, 3, 8, 0.32) 100%);
  mix-blend-mode: multiply;
  opacity: 0.55;
}

.boot-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  background: radial-gradient(ellipse at center, #1f1721 0%, #0d0a10 75%);
  z-index: 5;
  transition: opacity 400ms ease, visibility 400ms;
}

.boot-overlay.hidden { opacity: 0; visibility: hidden; }

.boot-kicker {
  margin: 0;
  font-size: 10px;
  letter-spacing: 0.5em;
  color: var(--ember-2);
  opacity: 0.75;
}

.boot-title {
  margin: 0;
  font-size: clamp(28px, 7vw, 54px);
  line-height: 0.94;
  text-align: center;
  letter-spacing: 0.14em;
  color: var(--cream);
  text-shadow: 0 0 24px rgba(232, 102, 61, 0.25);
}

.boot-hint {
  margin: 18px 0 0;
  font-size: 10px;
  letter-spacing: 0.35em;
  color: var(--dim);
  animation: pulse 1.8s ease-in-out infinite;
}

.boot-embers {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}

.boot-embers::before,
.boot-embers::after {
  content: "";
  position: absolute;
  width: 3px;
  height: 3px;
  left: 30%;
  bottom: 15%;
  background: var(--ember-2);
  box-shadow:
    40px -80px 0 rgba(243, 160, 91, 0.5),
    130px -160px 0 rgba(232, 102, 61, 0.4),
    -70px -220px 0 rgba(243, 160, 91, 0.35),
    220px -260px 0 rgba(232, 102, 61, 0.3),
    300px -120px 0 rgba(243, 160, 91, 0.4);
  animation: drift 8s linear infinite;
}

.boot-embers::after {
  left: 65%;
  animation-delay: -4s;
  animation-duration: 11s;
}

@keyframes drift {
  from { transform: translateY(40px); opacity: 0; }
  15% { opacity: 1; }
  to { transform: translateY(-240px); opacity: 0; }
}

@keyframes pulse {
  0%, 100% { opacity: 0.35; }
  50% { opacity: 1; }
}

#boot-error {
  max-width: 460px;
  padding: 24px;
  border: 1px solid var(--danger);
  background: #1f151a;
  color: var(--cream);
  font-size: 12px;
  line-height: 1.6;
  z-index: 10;
}

#boot-error h1 { font-size: 18px; margin: 0 0 8px; }
#boot-error pre {
  white-space: pre-wrap;
  color: var(--ember-2);
  background: #120e14;
  padding: 10px;
  overflow: auto;
  max-height: 160px;
}

.controls-strip {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 6px 18px;
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--dim);
  opacity: 0.7;
  padding-bottom: 2px;
}

kbd {
  font-family: inherit;
  border: 1px solid var(--line);
  border-bottom-color: #2a202e;
  background: #241c2a;
  padding: 1px 4px;
  border-radius: 2px;
  color: var(--cream);
  font-size: 8px;
}

.touch-controls {
  display: none;
  flex: 0 0 auto;
  align-items: center;
  justify-content: space-between;
  padding: 4px 6px 0;
  gap: 16px;
  z-index: 20;
}

.dpad {
  display: grid;
  grid-template-columns: repeat(3, 52px);
  grid-template-rows: repeat(3, 52px);
  gap: 3px;
  touch-action: none;
}

.tbtn {
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  border: 1px solid #5d4a5d;
  background: linear-gradient(180deg, rgba(48, 38, 53, 0.92), rgba(24, 19, 29, 0.94));
  color: var(--cream);
  font: 12px/1 var(--ui-font);
  border-radius: 4px;
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.08);
}

.tbtn:active, .tbtn.pressed {
  background: #3b2a3f;
  border-color: var(--ember-2);
  color: var(--gold);
}

.dpad .up { grid-area: 1 / 2; }
.dpad .left { grid-area: 2 / 1; }
.dpad .down { grid-area: 3 / 2; }
.dpad .right { grid-area: 2 / 3; }
.dpad-center {
  grid-area: 2 / 2;
  align-self: center;
  justify-self: center;
  width: 8px;
  height: 8px;
  background: #3a2e3f;
  border-radius: 50%;
}

.touch-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.tbtn.round {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  font-size: 18px;
  letter-spacing: 0.06em;
}

.tbtn.round.log { width: 40px; height: 40px; font-size: 9px; color: var(--dim); }
.tbtn.round.b { border-color: #684f5d; }
.tbtn.round.a { border-color: var(--ember); background: radial-gradient(circle at 35% 30%, #5a3128, #261a22); }

@media (max-width: 640px) {
  #app { padding: 8px; gap: 5px; }
  .topbar { padding: 0; }
  .brand-tag { display: none; }
  .brand-name { font-size: 11px; }
  #frame { padding: 4px; }
  .screen-glass { inset: 4px; }
}

/* ---- Phones and tablets (v3.27) ----
   main.js (fitCanvas) puts these classes on <html> and sizes the canvas:
     touch       a touch screen: the touch buttons show, the keyboard hints go
     phone-port  upright (and tablets either way): the game across the top, edge to edge,
                 a cross pad and the A/B buttons under it where thumbs rest
     phone-land  a phone on its side: the game fills the height, the pad sits in the left
                 gutter and A/B/LOG in the right, so nothing lies over the picture
     land-tight  a 16:9 phone on its side has no gutters to spare: the gutters shrink and
                 the pad laps over the picture's corner, see-through */
html.touch .touch-controls { display: flex; }
html.touch .controls-strip { display: none; }
html.touch .bottom-btn kbd { display: none; }
html.touch body { overscroll-behavior: none; -webkit-touch-callout: none; }

html.phone-port #app {
  padding: max(6px, env(safe-area-inset-top)) 0 max(10px, env(safe-area-inset-bottom));
  gap: 6px;
}
html.phone-port .topbar { padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); }
html.phone-port .brand-tag { display: none; }
html.phone-port #stage { align-items: flex-start; }
html.phone-port #frame,
html.phone-land #frame { padding: 0; border: 0; border-radius: 0; box-shadow: none; background: none; }
html.phone-port #frame::before,
html.phone-land #frame::before { display: none; }
html.phone-port .screen-glass,
html.phone-land .screen-glass { inset: 0; border-radius: 0; }
html.phone-port .touch-controls {
  align-items: flex-end;
  padding: 0 max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left));
}
html.phone-port .touch-actions {
  display: grid;
  grid-template-columns: 64px 74px;
  grid-template-rows: 46px 74px;
  gap: 8px 12px;
}
html.phone-port .tbtn.round.log { grid-area: 1 / 2; justify-self: end; width: 46px; height: 46px; font-size: 10px; }
html.phone-port .tbtn.round.b { grid-area: 2 / 1; align-self: start; width: 64px; height: 64px; font-size: 20px; }
html.phone-port .tbtn.round.a { grid-area: 2 / 2; width: 74px; height: 74px; font-size: 22px; }
html.phone-port .tbtn { font-size: 15px; }
html.phone-port .bottom-actions { padding-top: 4px; gap: 12px; }
html.phone-port .bottom-btn { height: 36px; min-width: 104px; font-size: 11px; }

html.phone-land { --gl: calc(140px + env(safe-area-inset-left)); --gr: calc(76px + env(safe-area-inset-right)); }
html.phone-land.land-tight { --gl: calc(64px + env(safe-area-inset-left)); --gr: calc(64px + env(safe-area-inset-right)); }
html.phone-land #app { display: block; position: relative; padding: 0; }
html.phone-land #stage { position: absolute; top: 0; bottom: 0; left: var(--gl); right: var(--gr); }
html.phone-land .topbar {
  position: absolute;
  top: max(6px, env(safe-area-inset-top));
  right: calc(6px + env(safe-area-inset-right));
  width: 64px;
  padding: 0;
  justify-content: flex-end;
  z-index: 21;
}
html.phone-land .brand,
html.phone-land .harakoo-link { display: none !important; }
html.phone-land .top-actions { gap: 4px; }
html.phone-land .icon-btn { width: 30px; height: 30px; font-size: 13px; }
html.phone-land .bottom-actions {
  position: absolute;
  top: max(6px, env(safe-area-inset-top));
  left: calc(6px + env(safe-area-inset-left));
  width: 128px;
  padding: 0;
  gap: 4px;
  justify-content: flex-start;
  z-index: 21;
}
html.phone-land .bottom-btn { flex: 1 1 0; height: 32px; padding: 0 2px; font-size: 9px; letter-spacing: 0.04em; }
html.phone-land .touch-controls { position: absolute; inset: 0; display: block; padding: 0; pointer-events: none; }
html.phone-land .dpad {
  position: absolute;
  left: calc(2px + env(safe-area-inset-left));
  bottom: max(12px, env(safe-area-inset-bottom));
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
  gap: 2px;
  pointer-events: auto;
}
html.phone-land .touch-actions {
  position: absolute;
  right: calc(8px + env(safe-area-inset-right));
  bottom: max(12px, env(safe-area-inset-bottom));
  flex-direction: column;
  gap: 8px;
  pointer-events: auto;
}
html.phone-land .tbtn.round.log { width: 40px; height: 40px; font-size: 9px; }
html.phone-land .tbtn.round.b { width: 54px; height: 54px; }
html.phone-land .tbtn.round.a { width: 60px; height: 60px; }
html.phone-land.land-tight .bottom-actions { width: 52px; flex-direction: column; }
html.phone-land.land-tight .bottom-btn { flex: 0 0 30px; width: 52px; font-size: 7px; letter-spacing: 0; white-space: normal; line-height: 1.1; }
html.phone-land.land-tight .topbar { width: 52px; }
html.phone-land.land-tight .top-actions { flex-direction: column; }
html.phone-land.land-tight .dpad { opacity: 0.62; }
html.phone-land.land-tight .touch-actions { right: calc(4px + env(safe-area-inset-right)); opacity: 0.8; }
html.phone-land.land-tight .tbtn.round.b { width: 50px; height: 50px; }
html.phone-land.land-tight .tbtn.round.a { width: 56px; height: 56px; }

@media (prefers-reduced-motion: reduce) {
  .boot-hint, .boot-embers::before, .boot-embers::after { animation: none; }
  .screen-glass { opacity: 0.3; }
}

.reduced-motion .boot-hint,
.reduced-motion .boot-embers::before,
.reduced-motion .boot-embers::after {
  animation: none !important;
}

.reduced-motion .screen-glass { opacity: 0.3; }
