:root {
  font-family: Inter, ui-rounded, -apple-system, BlinkMacSystemFont, "SF Pro Rounded", "Segoe UI", sans-serif;
  color: #1f2933;
  background: #f7efe5;
  font-synthesis: none;
  --surface: rgba(255, 255, 255, 0.92);
  --surface-strong: #ffffff;
  --text: #1f2933;
  --muted: #6b7280;
  --line: rgba(31, 41, 51, 0.10);
  --accent: #ed8f4c;
  --accent-strong: #d96c2c;
  --shadow: 0 24px 60px rgba(56, 42, 30, 0.15);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: #f7efe5; }
body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background:
    radial-gradient(circle at 20% 0%, rgba(255, 255, 255, 0.95), transparent 42%),
    linear-gradient(145deg, #f9f2e8, #f2e5d7);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior-y: contain;
}
button, input { font: inherit; }
button { touch-action: manipulation; }
button:focus-visible, input:focus-visible, a:focus-visible {
  outline: 3px solid rgba(42, 124, 180, 0.45);
  outline-offset: 2px;
}
[hidden] { display: none; }

.app-shell { min-height: 100vh; min-height: 100dvh; }
main { min-height: inherit; }

.setup-view {
  width: min(100%, 760px);
  margin: 0 auto;
  padding: max(22px, env(safe-area-inset-top)) 18px max(28px, env(safe-area-inset-bottom));
}
.setup-hero {
  display: grid;
  grid-template-columns: 58px 1fr;
  gap: 14px;
  align-items: center;
  margin: 8px 2px 20px;
}
.brand-mark {
  display: grid;
  place-items: center;
  width: 58px;
  height: 58px;
  border-radius: 20px;
  color: #fff;
  font-size: 30px;
  font-weight: 900;
  background: linear-gradient(145deg, #ffb267, #e87d3a);
  box-shadow: 0 14px 30px rgba(232, 125, 58, 0.30);
}
.eyebrow {
  margin: 0 0 4px;
  color: #956f50;
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
h1, h2, p { margin-top: 0; }
h1 { margin-bottom: 7px; font-size: clamp(27px, 7vw, 40px); line-height: 1.05; letter-spacing: -0.04em; }
.setup-copy { margin-bottom: 0; color: var(--muted); line-height: 1.45; }

.setup-card {
  padding: 18px;
  border: 1px solid rgba(255,255,255,0.75);
  border-radius: 28px;
  background: var(--surface);
  box-shadow: var(--shadow);
  backdrop-filter: blur(18px);
}
.field-label, .pet-fieldset legend {
  display: block;
  margin-bottom: 8px;
  font-size: 13px;
  font-weight: 800;
  color: #5e554e;
}
.name-input {
  width: 100%;
  min-height: 52px;
  padding: 0 16px;
  border: 1px solid var(--line);
  border-radius: 16px;
  color: var(--text);
  background: #fff;
  box-shadow: inset 0 1px 0 rgba(0,0,0,0.02);
}
.pet-fieldset { padding: 0; margin: 18px 0 16px; border: 0; }
.pet-picker {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}
.pet-option {
  min-height: 88px;
  padding: 11px 8px;
  border: 1px solid var(--line);
  border-radius: 19px;
  color: #433c36;
  background: #fff;
  box-shadow: 0 5px 12px rgba(57, 43, 30, 0.06);
  transition: transform 140ms ease, border-color 140ms ease, box-shadow 140ms ease, background 140ms ease;
}
.pet-option:active { transform: scale(0.98); }
.pet-option[aria-checked="true"] {
  border-color: rgba(224, 112, 48, 0.72);
  background: linear-gradient(180deg, #fff9f2, #fff1e1);
  box-shadow: 0 8px 18px rgba(224, 112, 48, 0.14), inset 0 0 0 1px rgba(224,112,48,0.18);
}
.pet-option .pet-emoji { display: block; margin-bottom: 5px; font-size: 34px; line-height: 1; }
.pet-option b { display: block; overflow: hidden; font-size: 12px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }

.primary-button, .secondary-button {
  width: 100%;
  min-height: 52px;
  border-radius: 17px;
  font-weight: 800;
}
.primary-button {
  border: 0;
  color: #fff;
  background: linear-gradient(180deg, #f5a45f, #df793a);
  box-shadow: 0 12px 24px rgba(223, 121, 58, 0.24);
}
.secondary-button {
  margin-top: 10px;
  border: 1px solid var(--line);
  color: #51483f;
  background: #fff;
}

.game-view {
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(8px, env(safe-area-inset-top)) 8px max(10px, env(safe-area-inset-bottom));
}
.device-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(330px, 1fr) auto auto;
  width: min(100%, 560px);
  min-height: calc(100vh - max(18px, env(safe-area-inset-top)) - max(18px, env(safe-area-inset-bottom)));
  min-height: calc(100dvh - max(18px, env(safe-area-inset-top)) - max(18px, env(safe-area-inset-bottom)));
  margin: 0 auto;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,0.82);
  border-radius: 34px;
  background: rgba(255, 248, 238, 0.96);
  box-shadow: 0 22px 58px rgba(74, 53, 34, 0.18);
}
.game-header {
  position: relative;
  z-index: 30;
  display: flex;
  gap: 8px;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 11px 13px;
  border-bottom: 1px solid rgba(65, 51, 39, 0.08);
  background: rgba(255, 250, 244, 0.92);
  backdrop-filter: blur(16px);
}
.identity-block { display: grid; min-width: 0; }
.pet-name { overflow: hidden; max-width: 135px; font-size: 15px; line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }
.stage-label { margin-top: 3px; color: #9a7152; font-size: 10px; font-weight: 900; letter-spacing: .11em; }
.header-controls { display: flex; align-items: center; gap: 6px; }
.clock-label { color: #665c53; font-size: 12px; font-variant-numeric: tabular-nums; }
.compact-button, .icon-button {
  min-height: 44px;
  border: 1px solid rgba(40, 31, 25, 0.08);
  color: #514a43;
  background: rgba(255,255,255,0.82);
}
.compact-button { min-width: 88px; padding: 0 10px; border-radius: 14px; font-size: 10px; font-weight: 900; letter-spacing: .04em; }
.icon-button { width: 44px; padding: 0; border-radius: 50%; font-weight: 900; }

.menu-panel {
  position: absolute;
  z-index: 90;
  top: 66px;
  right: 12px;
  width: 210px;
  overflow: hidden;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 18px;
  background: rgba(255,255,255,.98);
  box-shadow: 0 18px 40px rgba(31, 23, 18, 0.22);
}
.menu-panel button, .menu-panel a {
  display: block;
  width: 100%;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  border-bottom: 1px solid rgba(0,0,0,.06);
  color: #3f3a35;
  text-align: left;
  text-decoration: none;
  background: transparent;
  line-height: 46px;
}
.menu-panel button:last-of-type, .menu-panel a:last-child { border-bottom: 0; }

.pet-stage { position: relative; min-height: 330px; overflow: hidden; background: #b8d7dc; }
.status-chips {
  position: absolute;
  z-index: 25;
  top: 10px;
  left: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  max-width: calc(100% - 20px);
}
.status-chip {
  padding: 6px 9px;
  border: 1px solid rgba(255,255,255,.65);
  border-radius: 999px;
  color: #453e38;
  font-size: 10px;
  font-weight: 900;
  letter-spacing: .04em;
  background: rgba(255,255,255,.86);
  box-shadow: 0 5px 12px rgba(0,0,0,.08);
  backdrop-filter: blur(8px);
}
.message-bubble {
  position: absolute;
  z-index: 40;
  top: 10px;
  left: 50%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: min(calc(100% - 24px), 360px);
  min-height: 44px;
  padding: 9px 12px 9px 14px;
  transform: translateX(-50%);
  border: 1px solid rgba(255,255,255,.65);
  border-radius: 16px;
  color: #35312d;
  text-align: left;
  background: rgba(255,255,255,.91);
  box-shadow: 0 8px 24px rgba(0,0,0,.12);
  backdrop-filter: blur(12px);
}
.night-overlay {
  pointer-events: none;
  position: absolute;
  z-index: 20;
  inset: 0;
  opacity: 0;
  background: rgba(4, 9, 25, 0.70);
  transition: opacity 260ms ease;
}
.night-overlay.is-on { opacity: 1; }

.action-section {
  padding: 10px 10px 6px;
  background: #fff7ed;
}
.action-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.action-button {
  min-height: 58px;
  padding: 6px 4px;
  border: 1px solid rgba(86, 61, 40, 0.09);
  border-radius: 17px;
  color: #473f37;
  background: #fff;
  box-shadow: 0 5px 12px rgba(72, 50, 32, 0.05);
}
.action-button.is-selected { border-color: rgba(223,121,58,.65); box-shadow: inset 0 0 0 2px rgba(223,121,58,.18); }
.action-icon { display: block; margin-bottom: 3px; font-size: 21px; line-height: 1; }
.action-label { display: block; font-size: 10px; font-weight: 800; }

.abc-row {
  display: flex;
  justify-content: center;
  gap: 30px;
  padding: 8px 16px 13px;
  background: #fff7ed;
}
.abc-button {
  width: 54px;
  height: 44px;
  border: 1px solid rgba(83, 54, 35, 0.16);
  border-radius: 50%;
  color: #5a4637;
  font-size: 13px;
  font-weight: 900;
  background: linear-gradient(180deg,#fff,#f3dfcc);
  box-shadow: 0 5px 0 #dcc0a5, 0 7px 10px rgba(60,42,28,.09);
}
.abc-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #dcc0a5; }

.modal-backdrop {
  position: fixed;
  z-index: 200;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(24, 19, 16, 0.46);
  backdrop-filter: blur(7px);
}
.modal-card {
  width: min(100%, 440px);
  max-height: min(86vh, 720px);
  overflow: auto;
  padding: 20px;
  border: 1px solid rgba(255,255,255,.75);
  border-radius: 26px;
  background: #fffaf4;
  box-shadow: 0 28px 70px rgba(28, 19, 13, .30);
}
.modal-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.modal-header h2 { margin-bottom: 0; }
.metrics { display: grid; gap: 11px; margin-top: 18px; }
.metric-row { display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center; }
.metric-row label { font-size: 13px; font-weight: 800; }
.metric-row output { color: #74675b; font-size: 12px; font-weight: 700; }
.metric-row progress { grid-column: 1 / -1; width: 100%; height: 10px; accent-color: #e88d4b; }
.status-details { display: grid; grid-template-columns: 1fr auto; gap: 8px 14px; padding-top: 16px; border-top: 1px solid var(--line); }
.status-details dt { color: #76695e; }
.status-details dd { margin: 0; font-weight: 800; }
.death-card { text-align: center; }
.death-symbol { margin-bottom: 8px; font-size: 54px; }
.modal-actions { display: grid; gap: 8px; margin-top: 18px; }
.error-banner {
  position: fixed;
  z-index: 300;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  left: 12px;
  max-width: 680px;
  margin: auto;
  padding: 12px 14px;
  border-radius: 14px;
  color: #fff;
  background: #8d2e2e;
  box-shadow: 0 12px 30px rgba(0,0,0,.20);
}
.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (min-width: 640px) {
  .game-view { display: grid; place-items: center; padding: 22px; }
  .device-shell { min-height: 820px; max-height: 900px; }
  .pet-picker { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

@media (max-width: 370px) {
  .game-view { padding-right: 4px; padding-left: 4px; }
  .device-shell { border-radius: 28px; }
  .game-header { padding-right: 8px; padding-left: 8px; }
  .clock-label { display: none; }
  .compact-button { min-width: 80px; }
  .action-button { min-height: 54px; }
  .abc-row { gap: 23px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto; transition-duration: 0.01ms; animation-duration: 0.01ms; animation-iteration-count: 1; }
}
