:root {
  font-family: ui-rounded, "Trebuchet MS", system-ui, sans-serif;
  color: #432b47;
  background: #f9f2e8;
  --paper: #fff9ef;
  --ink: #432b47;
  --lilac: #ecdafa;
  --berry: #a94870;
  --line: #5c4161;
  --top: max(10px, env(safe-area-inset-top));
  --right: max(10px, env(safe-area-inset-right));
  --bottom: max(10px, env(safe-area-inset-bottom));
  --left: max(10px, env(safe-area-inset-left));
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body, #game { width: 100%; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { margin: 0; }
#game { position: relative; touch-action: none; user-select: none; }
#view { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }

button {
  color: inherit;
  font: inherit;
  font-weight: 800;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--paper);
  box-shadow: 0 3px 0 #432b4740;
  min-width: 44px;
  min-height: 44px;
  padding: 5px 10px;
  cursor: pointer;
  touch-action: none;
}
button:focus-visible { outline: 3px solid #7d49a4; outline-offset: 2px; }
button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #432b4740; }
button:disabled { opacity: .6; cursor: default; }

#play-hud { position: absolute; inset: 0; pointer-events: none; }
.dashboard { position: absolute; top: var(--top); left: var(--left); right: var(--right); width: min(100% - var(--left) - var(--right), 510px); margin-inline: auto; }
.meters {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
  padding: 4px 6px 4px 9px;
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 16px;
  font-size: clamp(11px, 3.25vw, 15px);
  white-space: nowrap;
}
.session { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.session button { pointer-events: auto; box-shadow: none; background: var(--lilac); }
#hearts { display: flex; gap: 1px; font-size: clamp(13px, 4.25vw, 21px); line-height: 1.25; }
.heart { display: grid; color: #c9b3c0; }
.heart > * { grid-area: 1 / 1; }
.heart b { width: var(--fill); overflow: hidden; color: var(--berry); }
#friend { overflow: hidden; text-overflow: ellipsis; font-weight: 800; }

#tasks { margin-top: 6px; display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 3px; }
.task {
  pointer-events: auto;
  min-width: 0;
  min-height: 49px;
  padding: 2px 0;
  font-size: clamp(8px, 2.55vw, 11px);
  border: 1.5px solid var(--line);
  border-radius: 10px;
  background: var(--paper);
}
.task[aria-pressed="true"] { background: var(--lilac); border-color: #824a9e; }
.task.complete { background: #e2f3d8; }
.ring {
  margin: 0 auto 1px;
  width: 26px;
  height: 26px;
  display: grid;
  place-items: center;
  font-size: 14px;
  border-radius: 50%;
  background: radial-gradient(circle, var(--paper) 55%, transparent 57%), conic-gradient(#8d57ad var(--progress, 0%), #e1d0d9 0);
}
.complete .ring { --progress: 100%; background-color: #b8e1a5; }

.actions { position: absolute; bottom: var(--bottom); right: var(--right); display: grid; justify-items: end; gap: 7px; z-index: 2; }
.actions button { pointer-events: auto; }
#action { min-height: 58px; min-width: 108px; padding-inline: 14px; background: #d6edb9; }
#send { background: #fff0bf; }
#look { background: var(--lilac); }
#look[aria-pressed="true"] { background: #d7b5ef; }
#wake-menu { display: flex; gap: 5px; }
#wake-menu button { min-width: 59px; border-radius: 50%; aspect-ratio: 1; padding: 3px; font-size: 11px; background: #ffe1e9; }
#wake-menu span, #wake-menu small { display: block; }
#wake-menu span { font-size: 16px; }
#wake-menu small { font-size: 10px; }
#joystick { position: absolute; width: 86px; height: 86px; transform: translate(-50%, -50%); display: grid; place-items: center; border: 2px solid #5c416178; border-radius: 50%; background: #fff9ef90; }
#joystick i { width: 34px; height: 34px; border: 2px solid var(--line); border-radius: 50%; background: var(--lilac); }

#mini {
  position: absolute;
  z-index: 3;
  bottom: var(--bottom);
  left: 50%;
  transform: translateX(-50%);
  width: min(100% - var(--left) - var(--right), 480px, (100dvh - 210px) * 1.333 + 24px);
  min-width: min(270px, 100% - var(--left) - var(--right));
  padding: 8px 10px;
  pointer-events: auto;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 5px 0 #432b4745, 0 12px 32px #432b4733;
}
.sheet-heading { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.sheet-heading h2 { margin: 0; font-size: 19px; }
.sheet-heading button { box-shadow: none; background: var(--lilac); }
#mini-hint { margin: 0 0 5px; font-size: 12px; }
#mini-canvas { display: block; width: 100%; aspect-ratio: 4 / 3; border-radius: 11px; background: #f7e8f4; touch-action: none; }
#mini-progress { display: block; width: 100%; height: 8px; margin-top: 6px; accent-color: #8d57ad; }
#play-hud:has(#mini:not([hidden])) .actions { bottom: var(--bottom); z-index: 1; }
@media (max-width: 640px) and (orientation: portrait) {
  #play-hud:has(#mini:not([hidden])) .actions { visibility: hidden; }
}
@media (orientation: landscape) and (max-height: 600px) {
  .dashboard { width: min(57vw, 480px); left: var(--left); right: auto; }
  #mini { width: min(45vw, (100dvh - 92px) * 1.333); min-width: 0; }
  #mini-canvas { max-height: calc(100dvh - var(--top) - var(--bottom) - 92px); }
  #play-hud:has(#mini:not([hidden])) .dashboard { width: min(27vw, 380px); }
  #play-hud:has(#mini:not([hidden])) #tasks { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  #play-hud:has(#mini:not([hidden])) #friend { display: none; }
}

#letterbox { position: absolute; inset: 0; border-block: min(7vh, 60px) solid #21172bd9; pointer-events: none; }
#skip { position: absolute; right: var(--right); bottom: var(--bottom); }
#speech { position: absolute; inset: 0; pointer-events: none; z-index: 4; }
.speech {
  position: absolute;
  transform: translate(-50%, -100%);
  width: max-content;
  max-width: min(52vw, 290px);
  background: var(--paper);
  border: 1.5px solid var(--line);
  border-radius: 12px;
  padding: 6px 10px;
  font-size: clamp(12px, 3vw, 16px);
  font-weight: 750;
  text-align: center;
}
.speech::after { content: ""; position: absolute; top: 100%; left: calc(50% - 4px); border: 5px solid transparent; border-top-color: var(--line); }
#overlay { position: absolute; inset: 0; z-index: 5; display: grid; place-items: center; padding: var(--top) var(--right) var(--bottom) var(--left); background: #f4e8f180; }
.panel {
  text-align: center;
  width: min(100%, 390px);
  max-height: 100%;
  overflow: auto;
  background: var(--paper);
  border: 2px solid var(--line);
  border-radius: 24px;
  box-shadow: 0 6px 0 #432b4755;
  padding: clamp(14px, 4vh, 32px);
}
#overlay-title { margin: 0; color: #59356b; font-size: clamp(26px, 8vw, 44px); line-height: 1.05; }
#overlay-symbol { margin: 0 0 5px; color: #976122; font-size: 34px; }
#overlay-note { margin: 12px 0; font-size: 15px; }
#overlay-button { min-width: 145px; background: var(--lilac); }
#overlay-detail { margin: 10px 0 0; font-size: 12px; }
#overlay-detail:empty, #overlay-symbol:empty { display: none; }
