* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; padding: 0; width: 100%; height: 100%; overflow: hidden;
  background: #1b2a1b; color: #fff;
  font-family: "Trebuchet MS", "Avenir Next", "Segoe UI", system-ui, sans-serif;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
  overscroll-behavior: none;
}
canvas#game { position: fixed; left: 0; top: 0; display: block; touch-action: none; }
.hidden { display: none !important; }
button { font-family: inherit; color: #fff; border: none; cursor: pointer; touch-action: manipulation; }

/* ---------- Screens ---------- */
.screen {
  position: fixed; inset: 0; z-index: 10; display: flex; overflow-y: auto;
  -webkit-overflow-scrolling: touch; touch-action: pan-y;
  padding: max(14px, env(safe-area-inset-top)) max(14px, env(safe-area-inset-right)) max(14px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  background: radial-gradient(circle at 50% 25%, #66bb6a 0%, #2e7d32 45%, #0d260f 100%);
  text-align: center;
}
.screen.overlay { background: rgba(8, 18, 8, 0.8); z-index: 20; }
.screen .inner { margin: auto; display: flex; flex-direction: column; align-items: center; gap: 12px; max-width: 900px; width: 100%; }
h1, h2, h3 { margin: 4px 0; text-shadow: 0 3px 0 rgba(0,0,0,.35); }
h2 { font-size: clamp(28px, 5vw, 44px); color: #ffd54f; }
h3 { font-size: 22px; }
.logo {
  font-size: clamp(48px, 11vw, 110px); line-height: 1; color: #ffd54f; letter-spacing: 2px;
  text-shadow: 0 4px 0 #e65100, 0 8px 0 #7f2b00, 0 12px 24px rgba(0,0,0,.5);
}
.title-dragon { width: min(70vw, 360px); height: auto; aspect-ratio: 3 / 2; }
.name-dragon { width: min(50vw, 240px); height: auto; aspect-ratio: 3 / 2; }
.best { font-size: 20px; color: #fff59d; min-height: 24px; }
.version { font-size: 13px; opacity: .6; }

.big {
  font-size: 28px; font-weight: bold; padding: 14px 40px; border-radius: 40px;
  background: linear-gradient(#ffca28, #f57c00);
  box-shadow: 0 6px 0 #a64b00, 0 8px 20px rgba(0,0,0,.4);
  text-shadow: 0 2px 0 rgba(0,0,0,.3);
}
.big:active { transform: translateY(4px); box-shadow: 0 2px 0 #a64b00; }
.big:disabled { filter: grayscale(1); opacity: .55; }
.mid {
  font-size: 20px; font-weight: bold; padding: 10px 24px; border-radius: 30px;
  background: #388e3c; box-shadow: 0 4px 0 #1b5e20;
}
.mid:active { transform: translateY(3px); box-shadow: 0 1px 0 #1b5e20; }
.nav-row { display: flex; gap: 16px; align-items: center; justify-content: center; flex-wrap: wrap; margin-top: 6px; }

/* Pick screen */
.row-label { font-size: 20px; font-weight: bold; }
.row-label span { font-size: 15px; font-weight: normal; opacity: .85; margin-left: 6px; }
.cards { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; }
.card {
  width: clamp(92px, 16vw, 140px); padding: 6px 4px 8px; border-radius: 16px;
  background: rgba(255,255,255,.14); border: 3px solid transparent;
  font-size: 14px; font-weight: bold; transition: transform .1s;
}
.card canvas { width: 100%; height: auto; aspect-ratio: 4 / 3; display: block; }
.card.selected { border-color: #ffd54f; background: rgba(255,213,79,.32); transform: scale(1.06); }
.pick-info { font-size: 20px; min-height: 28px; color: #fff59d; padding: 0 10px; }

/* Name screen */
.name-row { display: flex; gap: 10px; align-items: center; }
#name-input {
  font-size: 26px; font-family: inherit; padding: 10px 16px; border-radius: 16px;
  border: 3px solid #ffd54f; width: min(66vw, 340px); text-align: center;
  -webkit-user-select: text; user-select: text; color: #222;
}
.diet-row { display: flex; gap: 14px; flex-wrap: wrap; justify-content: center; }
.diet {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 12px 22px; min-width: 160px; border-radius: 20px;
  background: rgba(255,255,255,.14); border: 3px solid transparent;
}
.diet .ic { font-size: 34px; }
.diet b { font-size: 20px; }
.diet small { font-size: 15px; opacity: .9; }
.diet.selected { border-color: #ffd54f; background: rgba(255,213,79,.32); }

/* End + how to */
.end-text { font-size: 22px; line-height: 1.5; }
.howto ul { text-align: left; font-size: 18px; line-height: 1.45; max-width: 640px; padding-left: 10px; list-style: none; margin: 0; }
.howto li { margin: 4px 0; }
.howto .keys { font-size: 14px; opacity: .7; }

/* ---------- In-game controls ---------- */
#controls { position: fixed; inset: 0; z-index: 5; pointer-events: none; }
#joy-zone { position: absolute; left: 0; bottom: 0; width: 45%; height: 72%; pointer-events: auto; touch-action: none; }
#joy-hint {
  position: absolute; left: calc(24px + env(safe-area-inset-left)); bottom: calc(40px + env(safe-area-inset-bottom));
  font-size: 18px; font-weight: bold; padding: 8px 14px; border-radius: 20px;
  background: rgba(0,0,0,.35); animation: pulse 1.6s infinite;
}
@keyframes pulse { 50% { opacity: .45; } }
#joy-base {
  position: absolute; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%;
  background: rgba(255,255,255,.15); border: 3px solid rgba(255,255,255,.4); display: none;
}
#joy-knob {
  position: absolute; left: 50%; top: 50%; width: 62px; height: 62px; margin: -31px 0 0 -31px;
  border-radius: 50%; background: rgba(255,255,255,.6); box-shadow: 0 2px 8px rgba(0,0,0,.3);
}
#action-pad {
  --b: clamp(54px, 11.5vmin, 92px);
  position: absolute; right: calc(10px + env(safe-area-inset-right)); bottom: calc(10px + env(safe-area-inset-bottom));
  width: calc(var(--b) * 3.75); height: calc(var(--b) * 3.75); pointer-events: none;
}
.act {
  --s: 1;
  position: absolute; pointer-events: auto; touch-action: none;
  width: calc(var(--b) * var(--s)); height: calc(var(--b) * var(--s)); border-radius: 50%;
  background: rgba(0,0,0,.38); border: 3px solid rgba(255,255,255,.65);
  font-size: calc(var(--b) * 0.2); font-weight: bold; line-height: 1.05; padding: 0;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  transition: opacity .15s;
}
.act .ic { font-size: calc(var(--b) * var(--s) * 0.36); line-height: 1.1; }
.act.on { background: rgba(255,193,7,.6); transform: scale(.93); }
.act.cool { opacity: .45; }
.act[data-act="breath"] { --s: 1.45; right: 0; bottom: 0; background: rgba(230,81,0,.45); }
.act[data-act="bite"]   { right: calc(var(--b) * 1.6);  bottom: 0; }
.act[data-act="claw"]   { right: calc(var(--b) * 1.5);  bottom: calc(var(--b) * 1.1); }
.act[data-act="tail"]   { right: calc(var(--b) * 0.3);  bottom: calc(var(--b) * 1.6); }
.act[data-act="throw"]  { right: calc(var(--b) * 2.7);  bottom: calc(var(--b) * 0.5); }
.act[data-act="roar"]   { right: calc(var(--b) * 1.45); bottom: calc(var(--b) * 2.25); }
.act[data-act="fly"]    { right: calc(var(--b) * 0.2);  bottom: calc(var(--b) * 2.75); background: rgba(3,155,229,.45); }
#btn-pause {
  position: absolute; top: calc(10px + env(safe-area-inset-top)); right: calc(10px + env(safe-area-inset-right));
  width: 48px; height: 48px; border-radius: 50%; font-size: 22px; pointer-events: auto;
  background: rgba(0,0,0,.4); border: 2px solid rgba(255,255,255,.6);
}
#rotate-hint {
  position: fixed; left: 50%; top: 120px; transform: translateX(-50%); z-index: 8;
  font-size: 20px; font-weight: bold; padding: 12px 18px; border-radius: 20px;
  background: rgba(0,0,0,.6); pointer-events: none;
}
