@font-face {
  font-family: Montserrat;
  src: url('./assets/montserrat-semibold.ttf') format('truetype');
  font-weight: 600;
  font-display: swap;
}

:root {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  color: #303530;
  background: #f5f6f5;
  font-synthesis: none;
  --line: #dce0dc;
  --muted: #6c746e;
}

* { box-sizing: border-box; letter-spacing: 0; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body { -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button, .svg-click { cursor: pointer; }
button:focus-visible { outline: 2px solid #357863; outline-offset: 3px; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }

#game { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
#game-header { flex: none; height: 40px; padding: 0 12px; display: flex; align-items: center; justify-content: center; text-align: center; gap: 12px; background: #3b403c; color: white; font: 600 11px Montserrat, sans-serif; }
#main, #mobile-body-fridge { display: flex; flex: 1; min-width: 0; min-height: 0; }
#hud { width: 180px; flex: none; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #fff; padding-bottom: 14px; overflow-y: auto; }
.panel-heading { margin: 0; height: 34px; display: grid; place-items: center; flex: none; border-bottom: 1px solid var(--line); color: #555e57; background: #fafbfa; font: 600 11px Montserrat, sans-serif; text-transform: uppercase; }
#timer { display: block; margin: 20px 14px 24px; padding: 7px 3px; background: #eef1ee; border: 1px solid var(--line); border-radius: 4px; text-align: center; font-size: 23px; font-weight: 700; font-variant-numeric: tabular-nums; }
#vitals { display: flex; flex-direction: column; gap: 14px; padding: 0 14px; }
.stat { --stat: #7e8b83; display: grid; grid-template-columns: 1fr auto; gap: 5px; align-items: center; }
.stat-label { font-size: 10px; text-transform: uppercase; color: var(--muted); }
.stat-value { font-size: 12px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat-bar-bg { grid-column: 1 / -1; height: 10px; background: #eff1ef; border-radius: 3px; overflow: hidden; }
.stat-bar { height: 100%; background: var(--stat); transition: width .3s ease; }
.stat-ring { display: none; }
[data-stat="calories"] { --stat: #bd8c45; }
[data-stat="protein"] { --stat: #6788a7; }
[data-stat="muscle"] { --stat: #b46872; }
[data-stat="fat"] { --stat: #b3a04e; }
[data-stat="cardio"] { --stat: #5d9277; }
[data-stat="hunger"] { --stat: #b17d5e; }
[data-stat="hydration"] { --stat: #518ba1; }
[data-stat="fatigue"] { --stat: #9480a2; }
.stat.warning .stat-bar, .stat.warning .ring-fill { animation: pulse-warn .5s infinite alternate; }
@keyframes pulse-warn { to { opacity: .4; } }
.hud-buttons { display: flex; gap: 6px; margin: 24px 14px 0; }
.hud-btn { flex: none; width: 44px; height: 44px; padding: 0; display: grid; place-items: center; border: 1px solid #d1d8d2; border-radius: 4px; background: #f6f8f6; font-size: 13px; font-weight: 700; }
@media (hover: hover) and (pointer: fine) {
  .hud-btn:hover { background: #e8eee9; border-color: #a9b7ad; }
}
.hud-btn:active { background: #dfe7e1; }
.icon { width: 17px; height: 17px; stroke-width: 1.7; }
.hud-btn[data-action="body-model"] { display: flex; align-items: center; justify-content: center; gap: 0; }
.hud-btn[data-action="body-model"] .icon { width: 14px; height: 14px; stroke-width: 2; }
#mobile-buttons { display: none; }

#body-panel { flex: 1; min-width: 0; min-height: 0; position: relative; display: flex; align-items: center; justify-content: center; padding: 12px; background: #f5f6f5; overflow: hidden; }
#char-wrap { position: relative; width: 100%; height: 100%; min-width: 0; min-height: 0; flex: none; }
#char-wrap[data-renderer="svg"] { width: 260px; max-width: 100%; max-height: 560px; }
#char-wrap canvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: grab; outline: none; -webkit-tap-highlight-color: transparent; }
#char-wrap canvas.dragging { cursor: grabbing; }
.model-loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); font-size: 12px; }
.body-return { position: absolute; top: 12px; right: 12px; z-index: 3; }
.body-return .mannequin-icon { width: 18px; height: 34px; }
@media (min-width: 701px) {
  .hud-buttons .hud-btn { width: 33px; height: 33px; font-size: 9.75px; }
  .hud-buttons .icon { width: 12.75px; height: 12.75px; }
  .body-return { width: 33px; height: 33px; }
  .body-return .mannequin-icon { width: 13.5px; height: 25.5px; }
}
.body-exercise-target { position: absolute; width: 44px; height: 44px; transform: translate(-50%, -50%); padding: 0; border: 0; border-radius: 4px; outline: none; background: transparent; pointer-events: none; opacity: 0; }
.body-exercise-target:focus-visible { outline: none; }
.muscle-counters { position: absolute; inset: 0; pointer-events: none; }
.muscle-counter-leaders { position: absolute; inset: 0; width: 100%; height: 100%; overflow: hidden; }
.muscle-counter-leaders line { stroke: #a8afa9; stroke-width: 1; opacity: .65; }
.muscle-counter { position: absolute; display: grid; place-items: center; width: 36px; height: 36px; margin: 0; transform: translate(-50%, -50%); border-radius: 50%; background: #f5f6f5e8; color: #762f36; font-size: 13px; line-height: 1; font-weight: 700; font-variant-numeric: tabular-nums; }
.muscle-counter svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); }
.muscle-counter circle { fill: none; stroke: #862f3b; stroke-width: 2.5; stroke-linecap: butt; transition: stroke-dashoffset .18s ease; }
#character-svg { display: block; width: 100%; height: 100%; }
.svg-click { touch-action: manipulation; transition: filter .12s; outline: none; -webkit-tap-highlight-color: transparent; }
.svg-click:hover, .svg-click:focus-visible { filter: brightness(1.06); }
.svg-click:active { filter: brightness(1.2); }
.svg-click[aria-disabled="true"] { cursor: default; }
#svg-heart-group { transform-box: fill-box; transform-origin: center; animation: heartbeat 1.2s ease-in-out infinite; opacity: .7; }
#svg-heart-group.fast { animation-duration: .35s; }
@keyframes heartbeat { 0%, 100%, 30%, 60% { transform: scale(1); } 15% { transform: scale(1.18); } 45% { transform: scale(1.1); } }
#paused-state { position: absolute; top: 12px; left: 12px; color: var(--muted); font-size: 11px; }

#fridge-panel { width: 200px; flex: none; display: flex; flex-direction: column; overflow-y: auto; border-left: 1px solid var(--line); background: white; }
#fridge-content { display: flex; flex-direction: column; gap: 6px; padding: 5px 8px 12px; }
.food-section-label { font-size: 9px; text-transform: uppercase; color: var(--muted); padding: 5px 0; }
.food-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
.food-item { min-width: 0; height: 55px; padding: 3px 2px; border: 1px solid var(--line); border-radius: 4px; background: #fafbfa; text-align: center; }
#game[data-paused="true"] .food-item { pointer-events: none; }
.food-item:hover { background: #eef2ee; border-color: #a9b7ad; }
.food-item:active, .food-item.selected { background: #e0e9e1; }
.food-emoji { display: block; font-size: 20px; line-height: 22px; }
.food-name { display: block; font-size: 10px; font-weight: 600; line-height: 13px; }
.food-stats { display: block; font-size: 8px; color: var(--muted); line-height: 10px; }

#toast-container, #toast-container-warn { position: absolute; bottom: 8px; z-index: 5; pointer-events: none; max-width: calc(100% - 16px); }
#toast-container { left: 8px; }
#toast-container-warn { right: 8px; }
#toast-container:has(.toast):not(:empty) ~ #toast-container-warn { bottom: 48px; }
.toast { width: fit-content; max-width: 100%; padding: 6px 10px; border-radius: 6px; border: 1px solid #dce0dc; background: rgba(255,255,255,.96); color: #505a52; font-size: 11px; line-height: 1.4; box-shadow: 0 2px 8px #00000012; animation: toastInLeft .2s ease, toastPop .15s ease forwards; animation-delay: 0s, 1.35s; }
.toast.warn { color: #a43838; border-color: #e9c5c5; background: #fff1f0; animation-name: toastInRight, toastPop; }
@keyframes toastInLeft { from { opacity: 0; transform: translateX(-20px); } }
@keyframes toastInRight { from { opacity: 0; transform: translateX(20px); } }
@keyframes toastPop { 0% { opacity: 1; transform: scale(1); } 50% { transform: scale(1.1); } 100% { opacity: 0; transform: scale(0); } }
.flying-food { position: fixed; font-size: 42px; z-index: 10; pointer-events: none; transition: left .45s linear, top .45s linear; }
.flying-food.crumble { animation: foodCrumble .3s ease forwards; }
@keyframes foodCrumble { 30% { transform: scale(1.15); } 100% { transform: scale(0) rotate(40deg); opacity: 0; } }
.ex-flash { position: fixed; font-size: 22px; pointer-events: none; z-index: 10; animation: floatUp .7s ease forwards; }
@keyframes floatUp { to { transform: translateY(-36px) scale(1.4); opacity: 0; } }
.pulse-bright { animation: pulseBright .2s ease; }
@keyframes pulseBright { from { filter: brightness(1.8); } to { filter: brightness(1); } }

dialog { position: fixed; inset: 0; z-index: 20; border: 0; padding: 24px; width: 100%; max-width: none; height: 100%; max-height: none; margin: 0; background: #fff; color: inherit; }
dialog[open] { display: grid; place-items: center; }
dialog::backdrop { background: #fff; }
.splash-content { width: min(100%, 400px); text-align: center; }
.splash-content h1 { font: 600 30px/1.2 Montserrat, sans-serif; margin: 0 0 14px; }
.splash-content p { color: var(--muted); font-size: 14px; line-height: 1.6; }
#countdown-number { font-size: 88px; line-height: 1.2; font-weight: 700; color: #a94646; margin: 20px 0 8px; animation: countPulse .8s ease infinite; }
#splash-hint { min-height: 22px; }
@keyframes countPulse { 50% { transform: scale(1.08); opacity: .7; } }
#death-title { color: #a94646; }
#death-icon { font-size: 60px; margin-bottom: 12px; }
#death-time { margin: 20px 0 26px; font-variant-numeric: tabular-nums; }
#play-again { min-height: 48px; border: 1px solid #353d36; border-radius: 4px; background: #353d36; color: #fff; padding: 12px 32px; font-weight: 600; }
#play-again:hover { background: #4e5d51; }

@media (max-width: 700px) {
  #hud { width: 70px; padding: 8px 4px; overflow: hidden; }
  #hud .panel-heading, .hud-buttons { display: none; }
  #timer { margin: 0 0 9px; padding: 5px 1px; font-size: 16px; flex: none; }
  #vitals { padding: 0; flex: 1; min-height: 0; gap: 4px; justify-content: space-between; }
  .stat { display: grid; grid-template-columns: 1fr; grid-template-rows: 40px 12px; justify-items: center; gap: 2px; flex: none; }
  .stat-label { grid-column: 1; grid-row: 2; font-size: 8px; line-height: 12px; }
  .stat-value { grid-column: 1; grid-row: 1; font-size: 10px; z-index: 1; }
  .stat-bar-bg { display: none; }
  .stat-ring { display: block; grid-column: 1; grid-row: 1; width: 40px; height: 40px; transform: rotate(-90deg); }
  .ring-track, .ring-fill { fill: none; stroke-width: 4; }
  .ring-track { stroke: #edf0ed; }
  .ring-fill { stroke: var(--stat); stroke-linecap: round; transition: stroke-dashoffset .3s ease; }
  #mobile-body-fridge { flex-direction: column; }
  #body-panel { padding: 8px; }
  .muscle-counter { width: 30px; height: 30px; font-size: 11px; }
  #char-wrap { width: calc(100% - 48px); margin-right: 48px; }
  #char-wrap[data-renderer="svg"] { width: 200px; max-width: calc(100% - 26px); max-height: 400px; margin-right: 22px; }
  #mobile-buttons .hud-btn, .body-return { width: 33px; height: 33px; font-size: 9.75px; }
  #mobile-buttons .icon { width: 12.75px; height: 12.75px; }
  .body-return .mannequin-icon { width: 13.5px; height: 25.5px; }
  .body-return { top: 156px; right: 6px; }
  #mobile-buttons { position: absolute; right: 6px; top: 8px; display: flex; flex-direction: column; gap: 4px; z-index: 3; }
  #fridge-panel { width: 100%; overflow: visible; border-left: 0; border-top: 1px solid var(--line); }
  #fridge-panel .panel-heading, .food-section-label, .food-name, .food-stats { display: none; }
  #fridge-content { padding: 7px; gap: 4px; }
  .food-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 4px; }
  .food-item { height: 44px; padding: 0; }
  .food-emoji { font-size: 22px; line-height: 30px; }
  .toast { font-size: 10px; padding: 4px 8px; }
  #paused-state { left: 8px; top: 8px; font-size: 10px; }
}

@media (max-width: 700px) and (max-height: 570px) {
  #hud { padding-top: 5px; padding-bottom: 5px; }
  #timer { margin-bottom: 6px; }
  .stat { grid-template-rows: 38px 10px; gap: 1px; }
  .stat-ring { width: 38px; height: 38px; }
  .stat-label { line-height: 10px; }
}

@media (max-height: 490px) {
  html, body { overflow-y: auto; }
  #game { min-height: 490px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
