:root {
  --paper: #fbf8f1;
  --paper-2: #f7f3e8;
  --ink: #292f3d;
  --muted: #6f7687;
  --line: #dfe2e9;
  --yellow: #ffd970;
  --cyan: #78d4f0;
  --pink: #f58bb4;
  --green: #83d8a9;
  --red: #f07d7d;
  --shadow: 0 16px 40px rgba(41, 47, 61, 0.12);
  --radius: 18px;
  --font: ui-rounded, "SF Pro Rounded", "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--paper-2);
  -webkit-tap-highlight-color: transparent;
}

body {
  min-width: 320px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background:
    radial-gradient(circle at 20% 0%, rgba(120, 212, 240, 0.18), transparent 32rem),
    radial-gradient(circle at 80% 10%, rgba(245, 139, 180, 0.16), transparent 30rem),
    var(--paper-2);
  color: var(--ink);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.45;
  touch-action: manipulation;
}

button,
input,
select {
  font: inherit;
}

button {
  border: 0;
  color: inherit;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

img,
video,
canvas {
  display: block;
  max-width: 100%;
}

noscript {
  display: block;
  max-width: 32rem;
  margin: 4rem auto;
  padding: 1rem;
  background: white;
  border-radius: var(--radius);
}

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

.screen {
  position: relative;
  min-height: 100vh;
  min-height: 100dvh;
  padding: max(20px, env(safe-area-inset-top)) max(20px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(20px, env(safe-area-inset-left));
}

.screen--title {
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 1.5rem;
}

.title-panel {
  width: min(950px, 100%);
  padding: clamp(1.25rem, 4vw, 3rem);
  overflow: hidden;
  background: rgba(255, 255, 255, 0.82);
  border: 1px solid rgba(255, 255, 255, 0.75);
  border-radius: 32px;
  box-shadow: var(--shadow);
  text-align: center;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.title-logo {
  width: min(760px, 92%);
  height: auto;
  margin: 0 auto 1rem;
  filter: drop-shadow(0 12px 20px rgba(41, 47, 61, 0.12));
}

.title-tagline {
  margin: 0 auto 1.5rem;
  color: var(--muted);
  font-size: clamp(1rem, 2.6vw, 1.35rem);
}

.menu {
  display: grid;
  gap: 0.75rem;
  width: min(430px, 100%);
  margin: 0 auto;
}

.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.55rem;
  min-height: 48px;
  padding: 0.78rem 1.1rem;
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 999px;
  box-shadow: 0 5px 0 var(--ink);
  font-weight: 800;
  text-decoration: none;
  transition: transform 130ms ease, box-shadow 130ms ease, background 130ms ease;
  -webkit-user-select: none;
  user-select: none;
}

.btn:hover:not(:disabled),
.btn:focus-visible,
.btn:focus {
  transform: translateY(2px);
  box-shadow: 0 3px 0 var(--ink);
}

.btn:active:not(:disabled) {
  transform: translateY(5px);
  box-shadow: 0 0 0 var(--ink);
}

.btn:focus-visible,
.btn:focus,
.icon-btn:focus-visible,
.icon-btn:focus,
.tab:focus-visible,
.tab:focus {
  outline: 4px solid rgba(120, 212, 240, 0.45);
  outline-offset: 3px;
}

.btn--primary {
  background: var(--yellow);
}

.btn--pink {
  background: var(--pink);
}

.btn--cyan {
  background: var(--cyan);
}

.btn--small {
  min-height: 38px;
  padding: 0.5rem 0.85rem;
  font-size: 0.92rem;
}

.btn--wide {
  width: 100%;
}

.icon-btn {
  display: inline-grid;
  width: 42px;
  height: 42px;
  place-items: center;
  background: white;
  border: 2px solid var(--ink);
  border-radius: 50%;
  box-shadow: 0 3px 0 var(--ink);
  font-weight: 900;
  transition: transform 130ms ease, box-shadow 130ms ease;
}

.icon-btn:active {
  transform: translateY(3px);
  box-shadow: 0 0 0 var(--ink);
}

.hud {
  position: sticky;
  z-index: 10;
  top: max(10px, env(safe-area-inset-top));
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.7rem;
  width: min(1260px, 100%);
  margin: 0 auto 1rem;
  padding: 0.65rem;
  background: rgba(255, 255, 255, 0.84);
  border: 1px solid rgba(255, 255, 255, 0.78);
  border-radius: 22px;
  box-shadow: 0 10px 26px rgba(41, 47, 61, 0.1);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.hud__main {
  display: flex;
  flex: 1 1 380px;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.55rem 0.85rem;
}

.hud__badge {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.4rem 0.7rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 999px;
  font-weight: 800;
  white-space: nowrap;
}

.hud__energy {
  flex: 1 1 120px;
  min-width: 100px;
}

.hud__actions {
  display: flex;
  gap: 0.5rem;
  margin-left: auto;
}

.room {
  width: min(1260px, 100%);
  margin: 0 auto;
}

.room-stage {
  position: relative;
  display: grid;
  min-height: clamp(430px, 58vh, 650px);
  align-items: end;
  padding: clamp(1rem, 4vw, 3rem);
  overflow: hidden;
  background-color: #edf4f2;
  background-image: var(--room-bg);
  background-position: center;
  background-size: cover;
  border: 3px solid var(--ink);
  border-radius: 30px;
  box-shadow: var(--shadow);
  isolation: isolate;
}

.room-stage::before {
  position: absolute;
  inset: 0;
  z-index: -1;
  background: linear-gradient(180deg, transparent 35%, rgba(41, 47, 61, 0.38));
  content: "";
}

.room-stage__note {
  max-width: 28rem;
  padding: 1rem 1.2rem;
  background: rgba(255, 255, 255, 0.86);
  border: 2px solid rgba(41, 47, 61, 0.88);
  border-radius: 20px;
  box-shadow: 0 6px 0 rgba(41, 47, 61, 0.75);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
}

.room-stage__note h1 {
  margin: 0 0 0.35rem;
  font-size: clamp(1.4rem, 3vw, 2.1rem);
}

.room-stage__note p {
  margin: 0;
  color: var(--muted);
}

.characters {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.character-card {
  position: relative;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.9rem;
  align-items: center;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.9);
  border: 2px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 8px 0 rgba(41, 47, 61, 0.16);
  content-visibility: auto;
  contain-intrinsic-size: auto 150px;
}

.character-card__avatar {
  position: relative;
  display: grid;
  width: 84px;
  height: 84px;
  flex: 0 0 auto;
  place-items: center;
  overflow: hidden;
  background:
    radial-gradient(circle at 30% 20%, rgba(255,255,255,0.75), transparent 30%),
    var(--avatar-color, var(--cyan));
  border: 3px solid var(--ink);
  border-radius: 28% 40% 32% 42%;
  box-shadow: inset 0 -10px 0 rgba(41,47,61,0.1);
  font-size: 2.5rem;
  font-weight: 900;
}

.character-card__avatar::before,
.character-card__avatar::after {
  position: absolute;
  width: 11px;
  height: 11px;
  background: var(--ink);
  border-radius: 50%;
  content: "";
}

.character-card__avatar::before {
  top: 38px;
  left: 24px;
}

.character-card__avatar::after {
  top: 38px;
  right: 24px;
}

.character-card__face {
  position: relative;
  z-index: 1;
  transform: translateY(-13px);
}

.character-card__body {
  min-width: 0;
}

.character-card h2 {
  margin: 0;
  font-size: 1.2rem;
}

.character-card__mood {
  margin: 0.15rem 0 0.5rem;
  color: var(--muted);
  font-size: 0.92rem;
}

.meter {
  display: grid;
  gap: 0.3rem;
}

.meter__label {
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
}

.meter__track {
  height: 12px;
  overflow: hidden;
  background: #eceff3;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.meter__fill {
  width: var(--value, 0%);
  height: 100%;
  background: linear-gradient(90deg, var(--fill-a, var(--pink)), var(--fill-b, var(--yellow)));
  border-radius: inherit;
  transition: width 280ms ease;
}

.character-card__actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.45rem;
  grid-column: 1 / -1;
}

.facilities {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.75rem;
  margin-top: 1rem;
}

.facility {
  display: grid;
  min-height: 92px;
  align-content: center;
  gap: 0.2rem;
  padding: 0.85rem;
  background: white;
  border: 2px solid var(--ink);
  border-radius: 20px;
  box-shadow: 0 6px 0 rgba(41, 47, 61, 0.15);
  font-weight: 900;
  text-align: left;
}

.facility small {
  color: var(--muted);
  font-weight: 650;
}

.facility__icon {
  font-size: 1.7rem;
}

.toast-stack {
  position: fixed;
  z-index: 100;
  right: max(16px, env(safe-area-inset-right));
  bottom: max(16px, env(safe-area-inset-bottom));
  display: grid;
  gap: 0.55rem;
  width: min(380px, calc(100vw - 32px));
  pointer-events: none;
}

.toast {
  padding: 0.85rem 1rem;
  background: white;
  border: 2px solid var(--ink);
  border-left-width: 7px;
  border-radius: 16px;
  box-shadow: var(--shadow);
  animation: toast-in 220ms ease both;
}

.toast--success { border-left-color: var(--green); }
.toast--warn { border-left-color: var(--yellow); }
.toast--error { border-left-color: var(--red); }
.toast--info { border-left-color: var(--cyan); }

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

.modal-backdrop {
  position: fixed;
  z-index: 80;
  inset: 0;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  background: rgba(41, 47, 61, 0.42);
  animation: fade-in 150ms ease both;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
}

.modal {
  width: min(900px, 100%);
  max-height: min(860px, calc(100vh - 32px));
  max-height: min(860px, calc(100dvh - 32px));
  overflow: auto;
  padding: clamp(1rem, 3vw, 1.6rem);
  background: var(--paper);
  border: 3px solid var(--ink);
  border-radius: 28px;
  box-shadow: var(--shadow);
  animation: modal-in 170ms ease both;
  overscroll-behavior: contain;
}

.modal--narrow { width: min(560px, 100%); }
.modal--wide { width: min(1180px, 100%); }

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1rem;
}

.modal__header h2 {
  margin: 0;
  font-size: clamp(1.35rem, 3vw, 2rem);
}

.modal__body {
  display: grid;
  gap: 1rem;
}

@keyframes fade-in {
  from { opacity: 0; }
}

@keyframes modal-in {
  from { opacity: 0; transform: translateY(14px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

.dialogue {
  position: absolute;
  z-index: 3;
  right: clamp(1rem, 4vw, 3rem);
  bottom: clamp(1rem, 4vw, 3rem);
  left: clamp(1rem, 4vw, 3rem);
  display: grid;
  gap: 0.75rem;
  padding: 1rem;
  background: rgba(255, 255, 255, 0.93);
  border: 3px solid var(--ink);
  border-radius: 24px;
  box-shadow: 0 8px 0 rgba(41, 47, 61, 0.35);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.dialogue__speaker {
  display: inline-flex;
  width: max-content;
  padding: 0.32rem 0.75rem;
  background: var(--speaker-color, var(--cyan));
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-weight: 900;
}

.dialogue__text {
  min-height: 3.2em;
  margin: 0;
  font-size: clamp(1rem, 2.2vw, 1.22rem);
  white-space: pre-wrap;
}

.dialogue__controls {
  display: flex;
  justify-content: flex-end;
}

.tabs {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  padding-bottom: 0.35rem;
}

.tab {
  flex: 0 0 auto;
  padding: 0.58rem 0.9rem;
  background: white;
  border: 2px solid var(--line);
  border-radius: 999px;
  font-weight: 850;
}

.tab[aria-selected="true"] {
  background: var(--ink);
  border-color: var(--ink);
  color: white;
}

.grid {
  display: grid;
  gap: 0.8rem;
}

.grid--2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid--4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.panel,
.shop-item,
.inventory-item,
.job-card {
  padding: 0.9rem;
  background: white;
  border: 2px solid var(--line);
  border-radius: 18px;
}

.shop-item,
.job-card {
  display: grid;
  gap: 0.5rem;
}

.shop-item__top,
.job-card__top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.8rem;
}

.price {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.25rem 0.55rem;
  background: #fff6d6;
  border-radius: 999px;
  font-weight: 900;
}

.panel h3,
.shop-item h3,
.job-card h3 {
  margin: 0;
}

.muted {
  color: var(--muted);
}

.small {
  font-size: 0.9rem;
}

.kbd-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
}

.kbd {
  min-width: 2.1rem;
  padding: 0.22rem 0.5rem;
  background: #f1f3f7;
  border: 1px solid #cbd0da;
  border-bottom-width: 3px;
  border-radius: 7px;
  font-family: inherit;
  font-weight: 900;
  text-align: center;
}

.tv-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 250px;
  gap: 1rem;
}

.tv-screen {
  overflow: hidden;
  background: #10131c;
  border: 8px solid var(--ink);
  border-radius: 28px;
  box-shadow: inset 0 0 50px rgba(0, 0, 0, 0.5);
}

.tv-screen video {
  width: 100%;
  aspect-ratio: 16 / 9;
  object-fit: contain;
  background: #000;
}

.channel-list {
  display: grid;
  gap: 0.55rem;
  align-content: start;
}

.channel {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 0.65rem;
  align-items: center;
  padding: 0.65rem;
  background: white;
  border: 2px solid var(--line);
  border-radius: 15px;
  text-align: left;
}

.channel[aria-current="true"] {
  border-color: var(--ink);
  background: #f2fbff;
}

.channel__num {
  display: grid;
  width: 38px;
  height: 38px;
  place-items: center;
  background: var(--ink);
  border-radius: 12px;
  color: white;
  font-weight: 900;
}

.game-shell {
  display: grid;
  gap: 0.8rem;
  justify-items: center;
  min-height: 430px;
  padding: 1rem;
  background: #f4f6fa;
  border: 2px solid var(--ink);
  border-radius: 20px;
}

.game-shell canvas {
  width: min(760px, 100%);
  background: #fff;
  border: 2px solid var(--ink);
  border-radius: 16px;
  touch-action: none;
}

.game-shell__info {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.8rem;
  font-weight: 900;
}

.typing-target {
  display: grid;
  width: min(700px, 100%);
  gap: 0.9rem;
  align-content: center;
}

.typing-word {
  min-height: 76px;
  padding: 1rem;
  background: white;
  border: 2px solid var(--ink);
  border-radius: 18px;
  font-size: clamp(1.5rem, 5vw, 2.5rem);
  font-weight: 900;
  letter-spacing: 0.08em;
  text-align: center;
}

.typing-word .done {
  color: var(--green);
}

.typing-input {
  width: 100%;
  min-height: 56px;
  padding: 0.8rem 1rem;
  background: white;
  border: 2px solid var(--ink);
  border-radius: 999px;
  font-size: 1.25rem;
  font-weight: 800;
  text-align: center;
}

.typing-input:focus {
  outline: 4px solid rgba(120, 212, 240, 0.5);
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 1rem;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
}

.settings-row:last-child {
  border-bottom: 0;
}

.select {
  min-height: 42px;
  padding: 0.4rem 2.2rem 0.4rem 0.8rem;
  background: white;
  border: 2px solid var(--ink);
  border-radius: 12px;
  font-weight: 800;
}

.help-viewer {
  display: grid;
  gap: 0.8rem;
}

.help-viewer__image {
  overflow: hidden;
  background: white;
  border: 2px solid var(--ink);
  border-radius: 18px;
}

.help-viewer__image img {
  width: 100%;
}

.help-viewer__nav {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
}

.empty {
  padding: 1.2rem;
  background: #f7f8fb;
  border: 2px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  text-align: center;
}

@media (max-width: 900px) {
  .characters,
  .facilities,
  .grid--3,
  .grid--4 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .tv-layout {
    grid-template-columns: 1fr;
  }

  .channel-list {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 620px) {
  body {
    font-size: 15px;
  }

  .screen {
    padding-right: max(12px, env(safe-area-inset-right));
    padding-left: max(12px, env(safe-area-inset-left));
  }

  .characters,
  .facilities,
  .grid--2,
  .grid--3,
  .grid--4,
  .channel-list {
    grid-template-columns: 1fr;
  }

  .character-card {
    grid-template-columns: auto 1fr;
  }

  .hud__actions {
    width: 100%;
    margin-left: 0;
  }

  .room-stage {
    min-height: 500px;
  }

  .dialogue {
    position: fixed;
    right: 12px;
    bottom: 12px;
    left: 12px;
  }
}

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