.app-layout { display: flex; flex-wrap: wrap; gap: 2rem; justify-content: center; align-items: flex-start; max-width: 960px; margin: 0 auto; }
.app-layout > main { flex: 1 1 640px; min-width: 0; }

.tamagotchi-sidebar {
  flex: 0 0 300px;
  background: var(--bg-card, #fff);
  border-radius: 16px;
  padding: 1.25rem;
  box-shadow: var(--shadow-card, 0 2px 12px rgba(0, 0, 0, 0.06));
  border: 1px solid var(--border, rgba(0, 0, 0, 0.08));
  position: sticky;
  top: 2rem;
  transition: background 0.4s ease, border-color 0.4s ease, box-shadow 0.4s ease;
}
.tamagotchi-sidebar[data-time="night"] {
  background: var(--tamagotchi-night-bg, #1e293b);
  border-color: rgba(255, 255, 255, 0.08);
  box-shadow: 0 2px 16px rgba(0, 0, 0, 0.2);
}
.tamagotchi-sidebar[data-time="night"] .tamagotchi-title { color: var(--tamagotchi-night-text, #e2e8f0); }
.tamagotchi-sidebar[data-time="night"] .tamagotchi-bar label { color: var(--tamagotchi-night-muted, #94a3b8); }
.tamagotchi-sidebar[data-time="night"] .tamagotchi-status-bubble { background: rgba(30, 41, 59, 0.9); border-color: rgba(255,255,255,0.1); color: #cbd5e1; }
.tamagotchi-sidebar[data-time="night"] .tamagotchi-play-hint { color: #94a3b8; }
.tamagotchi-sidebar[data-time="night"] .tamagotchi-play-area { background: rgba(15, 23, 42, 0.6); border-color: rgba(255,255,255,0.1); }
.tamagotchi-sidebar-close { display: none; position: absolute; top: 0.5rem; right: 0.5rem; width: 2.5rem; height: 2.5rem; min-width: 44px; min-height: 44px; padding: 0; font-size: 1.5rem; line-height: 1; color: var(--text-muted, #666); background: transparent; border: none; cursor: pointer; border-radius: 8px; -webkit-tap-highlight-color: transparent; }
.tamagotchi-sidebar-close:hover { color: var(--text-primary, #1a1a1a); background: var(--border, rgba(0, 0, 0, 0.08)); }
.tamagotchi-mobile-toggle {
  display: none;
  position: fixed;
  bottom: 1.5rem;
  left: 50%;
  transform: translateX(-50%);
  width: auto;
  min-width: 3.5rem;
  height: 3.5rem;
  padding: 0 1.25rem;
  font-size: 1.1rem;
  font-weight: 500;
  border-radius: 2rem;
  background: var(--bg-card, #fff);
  border: 2px solid var(--border-input, #d4d4d4);
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.12);
  cursor: pointer;
  z-index: 100;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}
.tamagotchi-panel { position: relative; display: flex; flex-direction: column; }
.tamagotchi-title { font-size: 1rem; font-weight: 600; color: var(--text-primary, #1a1a1a); margin: 0 0 1rem; text-align: center; }

.tamagotchi-feed-row { display: flex; align-items: center; justify-content: center; gap: 0.75rem; margin-bottom: 1rem; min-height: 120px; }
.tamagotchi-avatar-and-status { position: relative; display: flex; flex-direction: column; align-items: center; }
.tamagotchi-status-bubble {
  font-size: 0.75rem; color: var(--text-muted, #555); background: var(--bg-body, #f5f5f4);
  border: 1px solid var(--border, rgba(0,0,0,0.08)); border-radius: 10px;
  padding: 0.35rem 0.6rem; margin-bottom: 0.35rem; max-width: 140px; min-height: 1.8em;
  text-align: center; line-height: 1.3; transition: opacity 0.3s, color 0.2s, background 0.2s;
  box-shadow: 0 1px 4px rgba(0,0,0,0.06);
  position: relative;
}
.tamagotchi-status-bubble::after {
  content: ''; position: absolute; bottom: -5px; left: 50%; margin-left: -5px;
  border: 5px solid transparent; border-top-color: inherit;
  border-top-color: var(--bubble-arrow, var(--bg-body, #f5f5f4));
}
.tamagotchi-status-bubble.status-urgent::after { border-top-color: rgba(254,226,226,0.95); }
.tamagotchi-status-bubble.status-want::after { border-top-color: rgba(254,243,199,0.95); }
.tamagotchi-status-bubble.status-happy::after { border-top-color: rgba(220,252,231,0.95); }
.tamagotchi-status-bubble:empty { opacity: 0; pointer-events: none; }
.tamagotchi-status-bubble.status-urgent { color: #b91c1c; border-color: rgba(185,28,28,0.3); background: rgba(254,226,226,0.95); }
.tamagotchi-status-bubble.status-want { color: #b45309; border-color: rgba(180,83,9,0.25); background: rgba(254,243,199,0.95); }
.tamagotchi-status-bubble.status-happy { color: #15803d; border-color: rgba(21,128,61,0.3); background: rgba(220,252,231,0.9); }
.tamagotchi-avatar-wrap {
  display: flex; align-items: center; justify-content: center; width: 120px; height: 120px;
  cursor: default; user-select: none; transition: transform 0.15s ease, filter 0.3s ease;
}
.tamagotchi-avatar-img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; pointer-events: none; }
.tamagotchi-avatar-wrap.eating .tamagotchi-avatar-img { animation: tamagotchi-nom 0.4s ease; }
@keyframes tamagotchi-nom { 50% { transform: scale(1.08); } 100% { transform: scale(1); } }
.tamagotchi-avatar-wrap:hover:not(.drop-target) { transform: scale(1.02); }
.tamagotchi-avatar-wrap.idle { animation: tamagotchi-idle 3s ease-in-out infinite; }
.tamagotchi-avatar-wrap.happy { animation: tamagotchi-bounce 0.5s ease; filter: brightness(1.08); }
.tamagotchi-avatar-wrap.sad .tamagotchi-avatar-img { filter: grayscale(0.4) brightness(0.88); }
.tamagotchi-avatar-wrap.sleeping { animation: none; }
.tamagotchi-avatar-wrap.sleeping .tamagotchi-avatar-img { filter: brightness(0.92); }
.tamagotchi-avatar-wrap.sleeping::after {
  content: ''; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 90%; height: 90%; border-radius: 50%; background: rgba(0,0,0,0.08);
  pointer-events: none;
}
@keyframes tamagotchi-idle { 0%, 100% { transform: rotate(-2deg); } 50% { transform: rotate(2deg); } }
@keyframes tamagotchi-bounce { 0% { transform: scale(1); } 50% { transform: scale(1.15); } 100% { transform: scale(1); } }

.tamagotchi-bowl-wrap { display: flex; flex-direction: column; align-items: center; gap: 0.5rem; }
.tamagotchi-feed-actions { display: flex; flex-direction: column; gap: 0.35rem; align-items: center; }
.tamagotchi-bowl {
  position: relative;
  width: 56px;
  height: 28px;
  background:
    radial-gradient(ellipse 70% 60% at 50% 0%, rgba(255,255,255,0.4) 0%, transparent 55%),
    radial-gradient(ellipse 90% 100% at 50% 100%, rgba(0,0,0,0.12) 0%, transparent 60%),
    linear-gradient(180deg, #d4d0cc 0%, #b8b2ac 15%, #9a948c 40%, #787168 100%);
  border: 2px solid #8b847a;
  border-radius: 50% 50% 50% 50% / 40% 40% 60% 60%;
  box-shadow:
    inset 0 2px 8px rgba(255,255,255,0.25),
    inset 0 -2px 6px rgba(0,0,0,0.15),
    0 2px 4px rgba(0,0,0,0.1);
  overflow: hidden;
}
.tamagotchi-kibble {
  position: absolute; left: 4px; right: 4px; bottom: 4px; top: 4px;
  display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: center; gap: 2px; padding: 0 2px; pointer-events: none; z-index: 1;
}
.tamagotchi-kibble-piece { width: 5px; height: 5px; border-radius: 50%; background: #a16207; opacity: 0; animation: kibble-fall 0.4s ease-out forwards; }
@keyframes kibble-fall { 0% { opacity: 0; transform: translateY(-8px) scale(0.5); } 100% { opacity: 0.95; transform: translateY(0) scale(1); } }
.tamagotchi-pour-btn, .tamagotchi-water-btn { padding: 0.4rem 0.6rem; font-size: 0.78rem; min-height: 36px; font-family: inherit; color: var(--text-primary); background: var(--bg-body, #f5f5f4); border: 1px solid var(--border-input, #d4d4d4); border-radius: 8px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.tamagotchi-pour-btn:hover, .tamagotchi-water-btn:hover { border-color: var(--accent, #22c55e); background: var(--accent-subtle, rgba(34, 197, 94, 0.08)); }
/* Общий стиль кнопок тамагочи: без своей подсветки, как у корм/причёска/игра */
.tamagotchi-brush-btn,
.tamagotchi-sleep-btn {
  display: block;
  width: 100%;
  padding: 0.5rem 0.6rem;
  font-size: 0.85rem;
  min-height: 44px;
  margin-bottom: 0.5rem;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--bg-body, #f5f5f4);
  border: 1px solid var(--border-input, #d4d4d4);
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-appearance: none;
  appearance: none;
  outline: none;
  box-shadow: none;
}
.tamagotchi-brush-btn:hover,
.tamagotchi-sleep-btn:hover:not(:disabled) {
  border-color: var(--accent, #22c55e);
  background: var(--accent-subtle, rgba(34, 197, 94, 0.08));
}
.tamagotchi-brush-btn:hover { border-color: #0ea5e9; background: rgba(14, 165, 233, 0.08); }
.tamagotchi-sleep-btn:hover:not(:disabled) { border-color: #6366f1; background: rgba(99, 102, 241, 0.08); }
.tamagotchi-sleep-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.tamagotchi-brush-btn:focus-visible,
.tamagotchi-sleep-btn:focus-visible {
  outline: 2px solid var(--border-input);
  outline-offset: 2px;
}

.tamagotchi-bars { display: flex; flex-direction: column; gap: 0.5rem; margin-bottom: 0.75rem; }
.tamagotchi-bar label { display: block; font-size: 0.8rem; color: var(--text-muted, #666); margin-bottom: 0.25rem; }
.tamagotchi-bar-track { height: 8px; background: var(--ring-track, #e5e7eb); border-radius: 4px; overflow: hidden; }
.tamagotchi-bar-fill { height: 100%; width: 80%; max-width: 100%; border-radius: 4px; transition: width 0.3s ease; }
#tamagotchi-hunger-fill { width: 80%; background: linear-gradient(90deg, #ea580c, #f97316); }
#tamagotchi-thirst-fill { width: 80%; background: linear-gradient(90deg, #0284c7, #0ea5e9); }
#tamagotchi-happiness-fill { width: 80%; background: linear-gradient(90deg, #15803d, #22c55e); }
#tamagotchi-energy-fill { width: 80%; background: linear-gradient(90deg, #a16207, #eab308); }
#tamagotchi-cleanliness-fill { width: 80%; background: linear-gradient(90deg, #6366f1, #818cf8); }
.tamagotchi-avatar-wrap.grooming .tamagotchi-avatar-img { animation: tamagotchi-groom 0.6s ease; }
@keyframes tamagotchi-groom { 0%, 100% { transform: scale(1); } 30% { transform: scale(1.05) rotate(-3deg); } 70% { transform: scale(1.05) rotate(3deg); } }

.tamagotchi-play-section { margin-top: 0.5rem; }
.tamagotchi-play-btn { display: block; width: 100%; padding: 0.6rem 0.75rem; font-size: 0.9rem; min-height: 48px; font-family: inherit; color: var(--text-primary); background: var(--bg-body, #f5f5f4); border: 1px solid var(--border-input, #d4d4d4); border-radius: 8px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.tamagotchi-play-btn:hover { border-color: var(--accent, #22c55e); background: var(--accent-subtle, rgba(34, 197, 94, 0.08)); }
.tamagotchi-play-btn.is-active { pointer-events: none; opacity: 0.8; }
.tamagotchi-play-hint { display: none; font-size: 0.8rem; color: var(--text-muted); margin: 0.5rem 0 0.25rem; }
.tamagotchi-play-hint.is-visible { display: block; }
.tamagotchi-play-area { position: relative; display: none; height: 140px; margin-top: 0.5rem; background: var(--bg-body, #f5f5f4); border-radius: 12px; border: 1px dashed var(--border-input, #d4d4d4); overflow: hidden; touch-action: manipulation; -webkit-user-select: none; user-select: none; min-height: 120px; }
.tamagotchi-play-area.is-active { display: block; }
.tamagotchi-mouse {
  position: absolute; width: 48px; height: 48px; min-width: 48px; min-height: 48px; left: 0; top: 0; margin: -24px 0 0 -24px; padding: 0; font-size: 2rem;
  display: flex; align-items: center; justify-content: center; background: none; border: none; border-radius: 50%; cursor: pointer;
  opacity: 0; pointer-events: none; transition: left 0.15s ease-out, top 0.15s ease-out, transform 0.1s ease;
  -webkit-tap-highlight-color: transparent; touch-action: manipulation;
}
.tamagotchi-mouse::before {
  content: ''; position: absolute; inset: -12px; border-radius: 50%; z-index: -1;
}
.tamagotchi-mouse.is-visible { opacity: 1; pointer-events: auto; }
.tamagotchi-mouse:hover { transform: scale(1.15); }
.tamagotchi-mouse:active { transform: scale(0.95); }

.mp-open-btn { display: block; width: 100%; margin-top: 1rem; padding: 0.6rem 0.75rem; font-size: 0.9rem; min-height: 48px; font-family: inherit; color: var(--text-primary); background: var(--bg-body, #f5f5f4); border: 1px solid var(--border-input, #d4d4d4); border-radius: 8px; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.mp-open-btn:hover { border-color: var(--accent, #22c55e); background: var(--accent-subtle, rgba(34, 197, 94, 0.08)); }

@media (max-width: 900px) {
  .app-layout {
    padding-bottom: calc(5rem + env(safe-area-inset-bottom, 0px));
    gap: 1rem;
  }
  .tamagotchi-sidebar {
    display: none;
    flex: none;
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: min(320px, calc(100vw - 1rem));
    max-height: 85vh;
    overflow-y: auto;
    overflow-x: hidden;
    -webkit-overflow-scrolling: touch;
    z-index: 200;
    border-radius: 16px 16px 0 0;
    padding: 1.25rem 1rem calc(1.5rem + env(safe-area-inset-bottom, 0px)) 1rem;
  }
  .tamagotchi-sidebar.is-open { display: block; }
  .tamagotchi-sidebar-close { display: block; }
  .tamagotchi-mobile-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.4rem;
    bottom: calc(1rem + env(safe-area-inset-bottom, 0px));
    left: 50%;
    transform: translateX(-50%);
    max-width: calc(100% - 2rem);
    min-width: 44px;
    min-height: 44px;
    padding: 0.5rem 1rem;
  }
  .tamagotchi-panel .tamagotchi-title { order: 0; }
  .tamagotchi-panel .tamagotchi-play-section { order: 1; margin-top: 0; margin-bottom: 0.75rem; }
  .tamagotchi-panel .mp-open-btn { order: 2; margin-top: 0; margin-bottom: 0.5rem; }
  .tamagotchi-panel .tamagotchi-feed-row { order: 3; min-height: 90px; margin-bottom: 0.5rem; }
  .tamagotchi-panel .tamagotchi-bars { order: 4; margin-bottom: 0.35rem; }
  .tamagotchi-panel .tamagotchi-brush-btn { order: 5; margin-bottom: 0.5rem; }
  .tamagotchi-avatar-wrap { width: 90px; height: 90px; }
  .tamagotchi-status-bubble { max-width: 120px; font-size: 0.7rem; }
  .tamagotchi-bars { gap: 0.4rem; margin-bottom: 0.5rem; }
  .tamagotchi-bar label { font-size: 0.75rem; }
  .tamagotchi-play-area { height: min(55vh, 300px); min-height: 200px; }
  .tamagotchi-mouse { width: 64px; height: 64px; min-width: 64px; min-height: 64px; margin: -32px 0 0 -32px; font-size: 2.5rem; }
  .tamagotchi-mouse::before { inset: -16px; }
}
[data-theme="dark"] .tamagotchi-status-bubble { background: var(--bg-card, #252525); }
[data-theme="dark"] .tamagotchi-status-bubble.status-urgent { color: #fca5a5; background: rgba(127,29,29,0.5); }
[data-theme="dark"] .tamagotchi-status-bubble.status-urgent::after { border-top-color: rgba(127,29,29,0.6); }
[data-theme="dark"] .tamagotchi-status-bubble.status-want { color: #fcd34d; background: rgba(120,53,15,0.4); }
[data-theme="dark"] .tamagotchi-status-bubble.status-want::after { border-top-color: rgba(120,53,15,0.5); }
[data-theme="dark"] .tamagotchi-status-bubble.status-happy { color: #86efac; background: rgba(21,128,61,0.25); }
[data-theme="dark"] .tamagotchi-status-bubble.status-happy::after { border-top-color: rgba(21,128,61,0.35); }

@media (prefers-reduced-motion: reduce) {
  .tamagotchi-avatar-wrap.idle, .tamagotchi-avatar-wrap.happy { animation: none; }
}
