/*
  PAPERWORLD - v1 - 2025-05-18
  Theme: Warm cream washi paper, deep ink typography, vermilion/indigo/gold accents.
  Zero external fonts/CDNs, 100dvh non-scrolling flex column layout.
*/

:root {
  --bg-cream: #f7f3eb;
  --bg-cream-card: #fbf8f2;
  --bg-cream-raised: #fffdf9;
  --bg-crease: #e8e0d1;
  --bg-crease-dark: #d6cab3;

  --ink-primary: #1e1b18;
  --ink-secondary: #585147;
  --ink-muted: #8c8273;
  --ink-border: #3b352e;
  --ink-faint-border: rgba(59, 53, 46, 0.16);

  --washi-vermilion: #b83a2c;
  --washi-vermilion-soft: #f8e5e2;
  --washi-indigo: #2c4465;
  --washi-indigo-soft: #e2e8f1;
  --washi-gold: #b38827;
  --washi-gold-soft: #faf0d8;
  --washi-cherry: #c95d7b;
  --washi-cherry-soft: #faebf0;

  --shadow-paper-flat: 0 1px 2px rgba(45, 38, 30, 0.08), 0 2px 6px rgba(45, 38, 30, 0.05);
  --shadow-paper-crease: 0 3px 0 var(--bg-crease-dark), 0 4px 10px rgba(35, 29, 20, 0.12);
  --shadow-dropdown: 0 10px 24px rgba(35, 29, 20, 0.16), 0 2px 4px rgba(35, 29, 20, 0.08);

  --font-stack: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace;
}

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  width: 100%;
  height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background-color: var(--bg-cream);
  color: var(--ink-primary);
  font-family: var(--font-stack);
  font-size: 14px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  display: flex;
  flex-direction: column;
  position: relative;
  background-image: 
    radial-gradient(ellipse at 20% 0%, rgba(243, 235, 220, 0.6) 0%, transparent 60%),
    radial-gradient(ellipse at 80% 100%, rgba(226, 216, 196, 0.4) 0%, transparent 60%);
}

/* ==========================================================================
   BANNER
   ========================================================================== */

.banner {
  flex-shrink: 0;
  height: 52px;
  padding: 0 18px;
  background: var(--bg-cream-raised);
  border-bottom: 1.5px solid var(--ink-faint-border);
  box-shadow: 0 2px 8px rgba(40, 32, 22, 0.04);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 100;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  user-select: none;
}

.brand-glyph {
  font-size: 1.25rem;
  line-height: 1;
  filter: drop-shadow(0 1px 1px rgba(0,0,0,0.1));
}

.brand-title {
  font-size: 0.95rem;
  font-weight: 800;
  letter-spacing: 0.22em;
  color: var(--ink-primary);
  text-transform: uppercase;
  margin: 0;
}

/* Search Input */
.search-wrap {
  position: relative;
  width: 260px;
  max-width: 50vw;
}

.search-input-box {
  display: flex;
  align-items: center;
  background: var(--bg-cream-card);
  border: 1.5px solid var(--ink-faint-border);
  border-radius: 6px;
  padding: 0 10px;
  height: 34px;
  box-shadow: inset 0 1px 2px rgba(40, 32, 22, 0.06);
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.search-input-box:focus-within {
  background: #ffffff;
  border-color: var(--washi-indigo);
  box-shadow: 0 0 0 2px rgba(44, 68, 101, 0.14), inset 0 1px 1px rgba(0,0,0,0.05);
}

.search-icon {
  font-size: 0.82rem;
  color: var(--ink-muted);
  margin-right: 6px;
  pointer-events: none;
}

.app-search-input {
  width: 100%;
  border: none;
  background: transparent;
  color: var(--ink-primary);
  font-family: inherit;
  font-size: 0.85rem;
  outline: none;
}

.app-search-input::placeholder {
  color: var(--ink-muted);
  font-style: normal;
}

/* Dropdown */
.search-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  width: 320px;
  max-width: 90vw;
  max-height: 380px;
  overflow-y: auto;
  background: var(--bg-cream-raised);
  border: 1.5px solid var(--ink-border);
  border-radius: 8px;
  box-shadow: var(--shadow-dropdown);
  padding: 6px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.search-dropdown.hidden {
  display: none;
}

.search-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: 5px;
  cursor: pointer;
  text-decoration: none;
  color: var(--ink-primary);
  background: transparent;
  border: 1px solid transparent;
  transition: background 0.1s ease, border-color 0.1s ease;
  user-select: none;
}

.search-item:hover,
.search-item.selected {
  background: var(--bg-crease);
  border-color: var(--ink-faint-border);
}

.search-item-icon {
  font-size: 1.15rem;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.search-item-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  flex-grow: 1;
}

.search-item-name {
  font-size: 0.84rem;
  font-weight: 600;
  color: var(--ink-primary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-item-label {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--washi-indigo);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-empty {
  padding: 12px;
  text-align: center;
  color: var(--ink-muted);
  font-size: 0.8rem;
  font-style: italic;
}

/* ==========================================================================
   STAGE (GAME MOUNT)
   ========================================================================== */

#stage {
  flex: 1 1 auto;
  min-height: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  background: var(--bg-cream);
  overflow: hidden;
}

#mount-game {
  width: 100%;
  height: 100%;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
}

/* ==========================================================================
   TAMAGOTCHI STRIP: TSURU
   ========================================================================== */

.pet-strip {
  flex-shrink: 0;
  min-height: 104px;
  height: auto;
  padding: 10px 18px;
  background: var(--bg-cream-card);
  border-top: 1.5px solid var(--ink-border);
  box-shadow: 0 -3px 8px rgba(45, 38, 30, 0.05);
  display: grid;
  grid-template-columns: 88px 1fr auto;
  align-items: center;
  gap: 16px;
  z-index: 50;
  user-select: none;
}

/* Left: Portrait */
.pet-portrait-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.pet-portrait-frame {
  width: 60px;
  height: 60px;
  background: var(--bg-cream-raised);
  border: 1.5px solid var(--ink-border);
  border-radius: 6px;
  box-shadow: 0 2px 0 var(--bg-crease-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  position: relative;
  transform-origin: 50% 90%;
  animation: gentle-sway 4.5s ease-in-out infinite;
}

.pet-portrait-frame.flutter {
  animation: action-flutter 0.45s ease-out;
}

.pet-avatar {
  width: 82%;
  height: 82%;
  object-fit: contain;
  pointer-events: none;
}

.pet-avatar.hidden {
  display: none;
}

.pet-avatar-fallback {
  width: 82%;
  height: 82%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.pet-avatar-fallback.hidden {
  display: none;
}

.crane-svg {
  width: 100%;
  height: 100%;
  filter: drop-shadow(0 2px 2px rgba(40, 32, 22, 0.15));
}

.pet-status-row {
  display: flex;
  align-items: center;
  gap: 4px;
}

.pet-name {
  font-size: 0.68rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--ink-secondary);
}

.pet-status-badge {
  font-size: 0.64rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 1px 5px;
  border-radius: 3px;
  background: var(--washi-gold-soft);
  color: var(--washi-gold);
  border: 1px solid rgba(179, 136, 39, 0.35);
}

.pet-status-badge.status-crisp {
  background: #eef7ee;
  color: #2b7430;
  border-color: rgba(43, 116, 48, 0.3);
}

.pet-status-badge.status-neat {
  background: var(--washi-indigo-soft);
  color: var(--washi-indigo);
  border-color: rgba(44, 68, 101, 0.3);
}

.pet-status-badge.status-crumpled {
  background: var(--washi-gold-soft);
  color: var(--washi-gold);
  border-color: rgba(179, 136, 39, 0.35);
}

.pet-status-badge.status-tattered {
  background: var(--washi-vermilion-soft);
  color: var(--washi-vermilion);
  border-color: rgba(184, 58, 44, 0.35);
}

/* Center: Stats, XP, Day */
.pet-center-col {
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-width: 0;
}

.pet-meta-row {
  display: flex;
  align-items: center;
  gap: 10px;
}

.pet-level-chip {
  font-size: 0.72rem;
  font-weight: 800;
  font-family: var(--font-mono);
  background: var(--ink-primary);
  color: #fff;
  padding: 2px 7px;
  border-radius: 4px;
  letter-spacing: 0.04em;
}

.xp-bar-track {
  flex: 1;
  height: 6px;
  background: var(--bg-crease);
  border: 1px solid var(--ink-faint-border);
  border-radius: 3px;
  overflow: hidden;
  box-shadow: inset 0 1px 1px rgba(0,0,0,0.06);
}

.xp-bar-fill {
  height: 100%;
  background: var(--washi-gold);
  transition: width 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

.pet-day-chip {
  font-size: 0.72rem;
  font-weight: 700;
  color: var(--ink-secondary);
  font-family: var(--font-mono);
  white-space: nowrap;
}

.pet-stats-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
}

.stat-item {
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.stat-label-wrap {
  display: flex;
  align-items: center;
  font-size: 0.72rem;
  color: var(--ink-secondary);
}

.stat-glyph {
  margin-right: 4px;
  font-size: 0.75rem;
}

.stat-name {
  font-weight: 600;
  margin-right: auto;
}

.stat-value {
  font-family: var(--font-mono);
  font-weight: 700;
  font-size: 0.75rem;
  color: var(--ink-primary);
}

.stat-bar-track {
  height: 7px;
  background: var(--bg-crease);
  border: 1px solid var(--ink-faint-border);
  border-radius: 4px;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(45, 38, 30, 0.08);
}

.stat-bar-fill {
  height: 100%;
  border-radius: 3px;
  transition: width 0.25s cubic-bezier(0.4, 0, 0.2, 1), background 0.2s ease;
}

.fill-crease {
  background: linear-gradient(90deg, #3d5a80, #2c4465);
}

.fill-cheer {
  background: linear-gradient(90deg, #d46b88, #c95d7b);
}

.fill-rest {
  background: linear-gradient(90deg, #c79c3d, #b38827);
}

/* Right: Care Buttons */
.pet-actions-col {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: nowrap;
}

.paper-btn {
  background: var(--bg-cream-raised);
  border: 1.5px solid var(--ink-border);
  border-radius: 6px;
  padding: 6px 10px;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 52px;
  box-shadow: 0 2px 0 var(--bg-crease-dark);
  transition: transform 0.06s ease, box-shadow 0.06s ease, background 0.1s ease;
  user-select: none;
}

.paper-btn:hover {
  background: #ffffff;
}

.paper-btn:active {
  transform: translateY(2px);
  box-shadow: 0 0 0 var(--bg-crease-dark);
}

.btn-icon {
  font-size: 1.05rem;
  line-height: 1.1;
}

.btn-label {
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--ink-primary);
}

/* Floating Action Particle */
.floating-delta {
  position: fixed;
  font-family: var(--font-mono);
  font-weight: 800;
  font-size: 0.85rem;
  pointer-events: none;
  z-index: 1000;
  color: var(--washi-vermilion);
  text-shadow: 0 1px 2px rgba(255, 255, 255, 0.8);
  animation: float-up-fade 0.85s cubic-bezier(0.2, 0.8, 0.2, 1) forwards;
}

/* Toast Container */
.toast-container {
  position: fixed;
  bottom: 116px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  pointer-events: none;
  z-index: 999;
}

.toast {
  background: var(--ink-primary);
  color: var(--bg-cream-raised);
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 0.82rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  box-shadow: 0 4px 14px rgba(30, 27, 24, 0.25);
  animation: toast-in 0.25s cubic-bezier(0.16, 1, 0.3, 1), toast-out 0.25s ease forwards 2.75s;
}

/* ==========================================================================
   ANIMATIONS
   ========================================================================== */

@keyframes gentle-sway {
  0%, 100% {
    transform: rotate(0deg);
  }
  25% {
    transform: rotate(-3.5deg) translateY(-1px);
  }
  75% {
    transform: rotate(3.5deg) translateY(-0.5px);
  }
}

@keyframes action-flutter {
  0% {
    transform: scale(1) rotate(0deg);
  }
  20% {
    transform: scale(1.16) translateY(-4px) rotate(-8deg);
  }
  50% {
    transform: scale(1.08) translateY(-2px) rotate(6deg);
  }
  75% {
    transform: scale(1.03) translateY(-1px) rotate(-3deg);
  }
  100% {
    transform: scale(1) rotate(0deg);
  }
}

@keyframes float-up-fade {
  0% {
    opacity: 0;
    transform: translate(-50%, 4px) scale(0.9);
  }
  15% {
    opacity: 1;
    transform: translate(-50%, -6px) scale(1.05);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -34px) scale(0.95);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(12px) scale(0.94);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes toast-out {
  from {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-8px) scale(0.94);
  }
}

/* ==========================================================================
   RESPONSIVE DESIGN (Thumb-first mobile polish)
   ========================================================================== */

@media (max-width: 680px) {
  .banner {
    padding: 0 12px;
    height: 48px;
  }
  
  .brand-title {
    font-size: 0.88rem;
    letter-spacing: 0.16em;
  }

  .search-wrap {
    width: 180px;
  }

  .pet-strip {
    grid-template-columns: 70px 1fr;
    grid-template-rows: auto auto;
    padding: 8px 10px;
    gap: 8px 10px;
    min-height: auto;
  }

  .pet-portrait-card {
    grid-column: 1 / 2;
    grid-row: 1 / 2;
  }

  .pet-portrait-frame {
    width: 48px;
    height: 48px;
  }

  .pet-center-col {
    grid-column: 2 / 3;
    grid-row: 1 / 2;
  }

  .pet-actions-col {
    grid-column: 1 / 3;
    grid-row: 2 / 3;
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 5px;
    width: 100%;
  }

  .paper-btn {
    min-width: 0;
    padding: 5px 2px;
  }

  .btn-label {
    font-size: 0.62rem;
  }

  .btn-icon {
    font-size: 0.95rem;
  }
}
