/**
 * Classic Tamagotchi device UX — icon rails, heart meters, attention call, A/B/C.
 * Biolume palette (teal/ink/amber/lime); no purple.
 */

:root {
  --tg-device-bezel: #0a1c24;
  --tg-device-face: #0e2832;
  --tg-device-rim: rgba(45, 212, 191, 0.35);
  --tg-device-amber: #fbbf24;
  --tg-heart-on: #f87171;
  --tg-heart-off: rgba(232, 244, 240, 0.18);
}

.tg-device {
  position: relative;
  display: grid;
  place-items: stretch;
  height: 100%;
  min-height: inherit;
}

.tg-device[hidden] {
  display: none !important;
}

.tg-device__bezel {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 0.35rem;
  height: 100%;
  padding: 0.55rem 0.55rem 0.65rem;
  border-radius: inherit;
  background:
    radial-gradient(ellipse 80% 50% at 50% 0%, rgba(45, 212, 191, 0.12), transparent 55%),
    linear-gradient(180deg, var(--tg-device-face), var(--tg-device-bezel));
  border: 1px solid var(--tg-device-rim);
  box-shadow:
    inset 0 1px 0 rgba(255, 255, 255, 0.06),
    0 18px 40px rgba(0, 0, 0, 0.35);
}

.tg-device__screen {
  position: relative;
  min-height: 0;
  border-radius: 1.1rem;
  overflow: hidden;
  border: 2px solid rgba(163, 230, 53, 0.22);
  background: #061218;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.45);
}

.tg-device__screen .tg-stage-frame {
  position: absolute;
  inset: 0;
}

/* Icon rails — classic top/bottom menu */
.tg-icon-rail {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.3rem;
  padding: 0.15rem 0.1rem;
}

.tg-icon-rail--bottom {
  grid-template-columns: repeat(4, 1fr);
}

.tg-tama-icon {
  position: relative;
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(6, 18, 24, 0.72);
  color: rgba(232, 244, 240, 0.78);
  border-radius: 0.85rem;
  min-height: 3.05rem;
  padding: 0.3rem 0.2rem;
  display: grid;
  justify-items: center;
  gap: 0.12rem;
  cursor: pointer;
  transition: border-color 0.15s ease, color 0.15s ease, background 0.15s ease, transform 0.12s ease;
}

.tg-tama-icon svg {
  width: 1.35rem;
  height: 1.35rem;
}

.tg-tama-icon__label {
  font-size: 0.62rem;
  font-weight: 750;
  letter-spacing: 0.02em;
  line-height: 1.1;
  text-align: center;
}

.tg-tama-icon:hover,
.tg-tama-icon:focus-visible {
  outline: none;
  border-color: rgba(45, 212, 191, 0.45);
  color: #ecfccb;
}

.tg-tama-icon.is-selected {
  border-color: rgba(163, 230, 53, 0.55);
  background: rgba(20, 83, 45, 0.45);
  color: #ecfccb;
  box-shadow: 0 0 0 1px rgba(163, 230, 53, 0.2) inset;
  transform: translateY(-1px);
}

.tg-tama-icon.is-suggest {
  animation: tg-tama-suggest 1.4s ease-in-out infinite;
}

.tg-tama-icon.is-boosted {
  box-shadow: 0 0 0 1px color-mix(in srgb, var(--tg-lime) 45%, transparent);
}

.tg-tama-icon__badge {
  position: absolute;
  top: 0.15rem;
  right: 0.2rem;
  min-width: 1rem;
  height: 1rem;
  padding: 0 0.22rem;
  border-radius: 999px;
  background: #fbbf24;
  color: #0a1c24;
  font-size: 0.58rem;
  font-weight: 800;
  line-height: 1rem;
  text-align: center;
}

.tg-tama-icon.is-urgent {
  border-color: rgba(251, 191, 36, 0.55);
  color: #fde68a;
}

@keyframes tg-tama-suggest {
  0%, 100% { box-shadow: 0 0 0 0 rgba(163, 230, 53, 0); }
  50% { box-shadow: 0 0 0 3px rgba(163, 230, 53, 0.18); }
}

@media (prefers-reduced-motion: reduce) {
  .tg-tama-icon.is-suggest { animation: none; }
}

/* Heart meters — classic Hungry / Happy glance */
.tg-hearts {
  position: absolute;
  left: 0.65rem;
  right: 0.65rem;
  bottom: 0.65rem;
  z-index: 17;
  display: grid;
  gap: 0.35rem;
  pointer-events: none;
}

.tg-hearts__row {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.28rem 0.45rem;
  border-radius: 999px;
  background: rgba(6, 18, 24, 0.78);
  border: 1px solid rgba(255, 255, 255, 0.08);
  backdrop-filter: blur(8px);
  width: fit-content;
  max-width: 100%;
}

.tg-hearts__row--happy {
  margin-left: auto;
}

.tg-hearts__label {
  font-size: 0.62rem;
  font-weight: 750;
  color: var(--tg-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.tg-hearts__dots {
  display: inline-flex;
  gap: 0.18rem;
}

.tg-heart {
  width: 0.78rem;
  height: 0.78rem;
  display: block;
  color: var(--tg-heart-off);
}

.tg-heart.is-on {
  color: var(--tg-heart-on);
}

.tg-hearts__row--happy .tg-heart.is-on {
  color: #a3e635;
}

/* Attention call — non-selectable, blinks like classic icon */
.tg-attention {
  position: absolute;
  top: 0.7rem;
  right: 0.7rem;
  z-index: 18;
  appearance: none;
  border: 1px solid rgba(251, 191, 36, 0.5);
  background: rgba(120, 53, 15, 0.55);
  color: #fde68a;
  border-radius: 999px;
  padding: 0.35rem 0.65rem;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
  animation: tg-attention-blink 0.9s steps(2, end) infinite;
}

.tg-attention[hidden] {
  display: none !important;
}

@keyframes tg-attention-blink {
  50% { opacity: 0.35; }
}

@media (prefers-reduced-motion: reduce) {
  .tg-attention { animation: none; opacity: 1; }
}

/* Status meter panel (classic scale icon) */
.tg-status-panel {
  position: absolute;
  inset: 0.65rem;
  z-index: 19;
  border-radius: 1rem;
  padding: 0.85rem 0.9rem;
  background: rgba(6, 18, 24, 0.94);
  border: 1px solid rgba(45, 212, 191, 0.28);
  backdrop-filter: blur(12px);
  display: grid;
  gap: 0.55rem;
  align-content: start;
  overflow: auto;
}

.tg-status-panel[hidden] {
  display: none !important;
}

.tg-status-panel__title {
  margin: 0;
  font-size: 0.95rem;
  color: #ecfccb;
}

.tg-status-panel__page {
  margin: 0;
  font-size: 0.68rem;
  color: var(--tg-muted);
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.tg-status-page {
  display: grid;
  gap: 0.55rem;
}

.tg-status-page__hint {
  margin: 0;
  font-size: 0.74rem;
  color: var(--tg-muted);
}

.tg-hearts__dots--lg .tg-heart {
  width: 1.15rem;
  height: 1.15rem;
}

/* Gen1 Meal / Snack submenu */
.tg-feed-menu {
  position: absolute;
  inset: 0.65rem;
  z-index: 19;
  border-radius: 1rem;
  padding: 0.9rem;
  background: rgba(6, 18, 24, 0.94);
  border: 1px solid rgba(45, 212, 191, 0.28);
  backdrop-filter: blur(12px);
  display: grid;
  gap: 0.65rem;
  align-content: center;
}

.tg-feed-menu[hidden] {
  display: none !important;
}

.tg-feed-menu__title {
  margin: 0;
  text-align: center;
  font-weight: 800;
  color: #ecfccb;
}

.tg-feed-menu__choices {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem;
}

.tg-feed-menu__btn {
  appearance: none;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(8, 28, 36, 0.9);
  color: rgba(232, 244, 240, 0.85);
  border-radius: 0.85rem;
  min-height: 3rem;
  font-weight: 750;
  cursor: pointer;
}

.tg-feed-menu__btn.is-selected {
  border-color: rgba(163, 230, 53, 0.55);
  background: rgba(20, 83, 45, 0.45);
  color: #ecfccb;
}

.tg-feed-menu__hint {
  margin: 0;
  text-align: center;
  font-size: 0.68rem;
  color: var(--tg-muted);
}

/* Items bag overlay on device screen */
.tg-item-menu {
  position: absolute;
  inset: 0.55rem;
  z-index: 20;
  border-radius: 1rem;
  padding: 0.75rem;
  background: rgba(6, 18, 24, 0.95);
  border: 1px solid rgba(251, 191, 36, 0.35);
  backdrop-filter: blur(12px);
  display: grid;
  gap: 0.45rem;
  align-content: start;
  overflow: auto;
  animation: tg-item-menu-in 0.28s cubic-bezier(0.2, 0.85, 0.25, 1) both;
}

.tg-item-menu[hidden] {
  display: none !important;
}

.tg-item-menu__title {
  margin: 0;
  text-align: center;
  font-weight: 800;
  color: #fde68a;
}

.tg-item-menu__lead,
.tg-item-menu__hint,
.tg-item-menu__empty {
  margin: 0;
  text-align: center;
  font-size: 0.68rem;
  color: var(--tg-muted);
}

.tg-item-menu__grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.45rem;
}

.tg-item-menu__card {
  appearance: none;
  display: grid;
  gap: 0.2rem;
  justify-items: center;
  padding: 0.45rem;
  border-radius: 0.85rem;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(8, 28, 36, 0.9);
  color: rgba(232, 244, 240, 0.9);
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.15s, background 0.15s;
}

.tg-item-menu__card img {
  width: 2.4rem;
  height: 2.4rem;
  object-fit: contain;
}

.tg-item-menu__name {
  font-size: 0.72rem;
  font-weight: 750;
}

.tg-item-menu__qty,
.tg-item-menu__fx {
  font-size: 0.62rem;
  opacity: 0.75;
}

.tg-item-menu__card.is-selected,
.tg-item-menu__card:hover {
  border-color: rgba(251, 191, 36, 0.55);
  background: rgba(120, 53, 15, 0.35);
  transform: translateY(-1px);
}

@keyframes tg-item-menu-in {
  from { opacity: 0; transform: scale(0.96) translateY(6px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

@media (prefers-reduced-motion: reduce) {
  .tg-item-menu { animation: none; }
}

/* Gen1 clock (B with no selection) */
.tg-clock {
  position: absolute;
  inset: 0.65rem;
  z-index: 19;
  border-radius: 1rem;
  padding: 1.1rem;
  background: rgba(6, 18, 24, 0.94);
  border: 1px solid rgba(45, 212, 191, 0.28);
  display: grid;
  place-content: center;
  gap: 0.35rem;
  text-align: center;
}

.tg-clock[hidden] {
  display: none !important;
}

.tg-clock__label {
  margin: 0;
  font-size: 0.72rem;
  color: var(--tg-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.tg-clock__time {
  margin: 0;
  font-size: 2rem;
  font-weight: 800;
  color: #ecfccb;
  font-variant-numeric: tabular-nums;
}

.tg-stage-frame[data-lights="on"] .tg-light-overlay {
  opacity: 0.35;
  background: radial-gradient(circle at 50% 20%, rgba(251, 191, 36, 0.35), transparent 55%);
}

.tg-stage-frame[data-lights="off"] .tg-light-overlay,
.tg-stage-frame.is-lights-out .tg-light-overlay,
#tg-stage.is-lights-out {
  filter: brightness(0.62) saturate(0.85);
}

.tg-stage-frame[data-lights="off"],
.tg-stage-frame.is-lights-out {
  box-shadow: inset 0 0 2.5rem rgba(2, 8, 16, 0.55);
}

.tg-stage-frame[data-lights="off"] .tg-light-overlay {
  opacity: 0.55;
  background: radial-gradient(circle at 50% 10%, rgba(15, 23, 42, 0.15), rgba(2, 6, 14, 0.72) 70%);
}

.tg-stage-frame.is-sleeping,
#tg-stage.is-sleeping {
  filter: brightness(0.55) saturate(0.8);
  box-shadow: inset 0 0 3.5rem rgba(15, 10, 40, 0.72);
}

.tg-sleep-banner {
  position: absolute;
  left: 50%;
  bottom: 0.85rem;
  z-index: 18;
  display: flex;
  align-items: center;
  gap: 0.65rem;
  max-width: min(92%, 22rem);
  padding: 0.55rem 0.7rem;
  border-radius: 0.85rem;
  background: color-mix(in srgb, #0f172a 82%, transparent);
  border: 1px solid color-mix(in srgb, #818cf8 35%, transparent);
  box-shadow: 0 10px 28px rgba(2, 6, 23, 0.45);
  color: #e2e8f0;
  transform: translateX(-50%);
  backdrop-filter: blur(8px);
}

.tg-sleep-banner[hidden] {
  display: none !important;
}

.tg-sleep-banner__glyph {
  font-size: 1.25rem;
  line-height: 1;
}

.tg-sleep-banner__body {
  display: grid;
  gap: 0.1rem;
  min-width: 0;
  flex: 1;
}

.tg-sleep-banner__title {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.tg-sleep-banner__time {
  font-size: 0.72rem;
  opacity: 0.85;
  font-variant-numeric: tabular-nums;
}

.tg-sleep-banner__wake {
  flex-shrink: 0;
  font-size: 0.72rem;
  padding: 0.35rem 0.6rem;
}

.tg-tama-icon.is-wake,
.tg-care-btn.is-wake {
  box-shadow: 0 0 0 1px color-mix(in srgb, #fbbf24 45%, transparent);
}

.tg-tama-icon.is-urgent[data-device="discipline"] {
  animation: tg-discipline-pulse 1.1s ease-in-out infinite;
}

@keyframes tg-discipline-pulse {
  0%,
  100% {
    transform: scale(1);
    box-shadow: 0 0 0 0 rgba(248, 113, 113, 0.35);
  }
  50% {
    transform: scale(1.06);
    box-shadow: 0 0 0 0.35rem rgba(248, 113, 113, 0);
  }
}

@media (prefers-reduced-motion: reduce) {
  .tg-tama-icon.is-urgent[data-device="discipline"] {
    animation: none;
  }
}

.tg-status-panel__row {
  display: grid;
  gap: 0.25rem;
}

.tg-status-panel__head {
  display: flex;
  justify-content: space-between;
  font-size: 0.74rem;
  color: var(--tg-muted);
}

.tg-status-panel__head strong {
  color: #ecfccb;
}

/* A / B / C — classic three-button nav */
.tg-abc {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.55rem;
  padding: 0.25rem 0.35rem 0.1rem;
}

.tg-abc__btn {
  appearance: none;
  border: 1px solid rgba(45, 212, 191, 0.28);
  background: radial-gradient(circle at 50% 30%, rgba(45, 212, 191, 0.18), rgba(8, 28, 36, 0.95));
  color: #ecfccb;
  border-radius: 999px;
  min-height: 2.85rem;
  font-weight: 800;
  font-size: 0.95rem;
  letter-spacing: 0.06em;
  cursor: pointer;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.28);
  transition: transform 0.12s ease, border-color 0.15s ease;
}

.tg-abc__btn:hover,
.tg-abc__btn:focus-visible {
  outline: none;
  border-color: rgba(163, 230, 53, 0.45);
  transform: translateY(-1px);
}

.tg-abc__btn:active {
  transform: translateY(1px);
}

.tg-abc__hint {
  grid-column: 1 / -1;
  margin: 0;
  text-align: center;
  font-size: 0.68rem;
  color: var(--tg-muted);
}

/* Play shell integration */
.tg-play__stage.tg-play__stage--device {
  background: transparent;
  border-bottom: none;
}

.tg-play__stage--device .tg-stage-hud {
  top: 3.35rem;
}

/* Device rails + hearts are the only care grammar — never dual chrome. */
.tg-play__stage--device ~ .tg-play__hud .tg-needs-block,
.tg-play__stage--device ~ .tg-play__hud .tg-care-zone,
.tg-play:has(.tg-play__stage--device) .tg-play__hud .tg-needs-block,
.tg-play:has(.tg-play__stage--device) .tg-play__hud .tg-care-zone {
  display: none !important;
}

.tg-play__hud .tg-suggest {
  order: -1;
}

@media (min-width: 960px) {
  .tg-device__bezel {
    padding: 0.75rem;
    gap: 0.45rem;
  }

  .tg-tama-icon {
    min-height: 3.35rem;
  }
}

@media (max-width: 859px) {
  .tg-play[data-has-pet="1"] {
    grid-template-rows: minmax(58vh, 1fr) auto;
  }

  .tg-play__stage--device {
    min-height: 58vh;
  }

  .tg-play__hud {
    padding-bottom: calc(0.65rem + var(--tg-tabbar-h, 4.15rem) + env(safe-area-inset-bottom, 0px));
  }
}
