:root {
  --ink: #2c2430;
  --muted: #7f6f7f;
  --paper: #fff9f0;
  --rose: #f7b2c2;
  --gold: #f5c962;
  --green: #7ebf89;
  --blue: #8fc9e8;
  --lav: #b7a3da;
  --shadow: rgba(39, 29, 43, 0.18);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 247, 238, 0.94), rgba(243, 251, 244, 0.9)),
    repeating-linear-gradient(0deg, rgba(247, 178, 194, 0.08), rgba(247, 178, 194, 0.08) 1px, transparent 1px, transparent 8px);
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body.touch-hidden .touch-controls {
  display: none !important;
}

button,
label.file-button {
  border: 2px solid #4b394f;
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  border-radius: 8px;
  padding: 0.58rem 0.75rem;
  box-shadow: 0 3px 0 #4b394f;
  cursor: pointer;
  user-select: none;
}

button:active,
label.file-button:active {
  transform: translateY(2px);
  box-shadow: 0 1px 0 #4b394f;
}

.title-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(260px, 360px);
  gap: 28px;
  align-items: center;
  padding: clamp(18px, 5vw, 64px);
  background:
    linear-gradient(180deg, rgba(255, 249, 240, 0.9), rgba(243, 251, 244, 0.92)),
    repeating-linear-gradient(90deg, rgba(245, 201, 98, 0.12), rgba(245, 201, 98, 0.12) 1px, transparent 1px, transparent 12px);
}

.title-screen.hidden {
  display: none;
}

.title-art {
  min-height: 58vh;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.eyebrow {
  margin: 0 0 8px;
  color: #bd5f87;
  font-size: 0.86rem;
  font-weight: 800;
}

.title-art h1 {
  margin: 0;
  color: #453044;
  font-size: clamp(4.2rem, 15vw, 11rem);
  line-height: 0.82;
  text-shadow: 5px 5px 0 #ffdfe8, 9px 9px 0 rgba(245, 201, 98, 0.35);
}

.subtitle {
  margin: 18px 0 0;
  color: var(--muted);
  font-size: clamp(1.1rem, 3vw, 2rem);
  font-weight: 800;
}

.title-menu,
.pause-actions {
  display: grid;
  gap: 10px;
}

.title-menu button,
.pause-actions button {
  width: 100%;
  text-align: left;
  padding: 0.72rem 0.9rem;
}

.title-hint {
  grid-column: 1 / -1;
  margin: 0;
  color: var(--muted);
  font-weight: 700;
}

.shell {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 16px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.topbar h1 {
  margin: 0;
  font-size: clamp(2rem, 5vw, 4.3rem);
  line-height: 0.92;
  color: #453044;
  text-shadow: 3px 3px 0 #ffdfe8;
}

.topbar p {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font-weight: 700;
}

.top-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  justify-content: end;
}

.screen-frame {
  position: relative;
  width: 100%;
  aspect-ratio: 5 / 3;
  border: 4px solid #4b394f;
  border-radius: 8px;
  overflow: hidden;
  background: #222034;
  box-shadow: 0 18px 48px var(--shadow);
}

.pause-overlay {
  position: fixed;
  inset: 0;
  z-index: 12;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(44, 36, 48, 0.42);
}

.pause-card {
  width: min(380px, 100%);
  background: var(--paper);
  border: 3px solid #4b394f;
  border-radius: 8px;
  padding: 16px;
  box-shadow: 0 18px 48px rgba(20, 10, 23, 0.25);
}

.pause-card h2 {
  margin: 0 0 14px;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}

.panel {
  display: grid;
  gap: 12px;
  align-content: start;
}

.panel section {
  background: rgba(255, 253, 248, 0.9);
  border: 2px solid rgba(75, 57, 79, 0.2);
  border-radius: 8px;
  padding: 12px;
}

.panel h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.panel p {
  margin: 0.3rem 0;
  color: var(--muted);
  line-height: 1.35;
}

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

.pet-face {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 8px;
  background: #fff3b0;
  border: 2px solid #4b394f;
  color: #d67b9a;
  font-size: 1.4rem;
}

.dialogue {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 18px;
  min-height: 106px;
  padding: 14px;
  border: 3px solid #4b394f;
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.96);
  box-shadow: 0 8px 0 rgba(75, 57, 79, 0.18);
}

.dialogue .speaker {
  color: #bd5f87;
  font-weight: 800;
  margin-bottom: 6px;
}

.dialogue .line {
  min-height: 42px;
  font-size: clamp(0.9rem, 2.3vw, 1.08rem);
  line-height: 1.38;
}

.dialogue button {
  position: absolute;
  right: 12px;
  bottom: 10px;
  padding: 0.38rem 0.7rem;
}

.touch-controls {
  margin-top: 12px;
  display: none;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
}

.dpad {
  width: 132px;
  height: 132px;
  display: grid;
  grid-template-columns: repeat(3, 44px);
  grid-template-rows: repeat(3, 44px);
}

.dpad button {
  padding: 0;
  border-radius: 8px;
}

.dpad [data-dir="up"] {
  grid-column: 2;
}

.dpad [data-dir="left"] {
  grid-column: 1;
  grid-row: 2;
}

.dpad [data-dir="down"] {
  grid-column: 2;
  grid-row: 3;
}

.dpad [data-dir="right"] {
  grid-column: 3;
  grid-row: 2;
}

.action {
  width: 96px;
  height: 96px;
  border-radius: 50%;
  background: #ffe2eb;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(44, 36, 48, 0.45);
  z-index: 10;
}

.modal-card {
  width: min(720px, 100%);
  max-height: 92vh;
  overflow: auto;
  background: var(--paper);
  border: 3px solid #4b394f;
  border-radius: 8px;
  padding: 14px;
  box-shadow: 0 18px 48px rgba(20, 10, 23, 0.25);
}

.modal-card.wide {
  width: min(1040px, 100%);
}

.modal-card img {
  width: 100%;
  height: auto;
  display: block;
  image-rendering: auto;
  border-radius: 6px;
  border: 2px solid rgba(75, 57, 79, 0.16);
}

.modal-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 12px;
}

.modal-head h2 {
  margin: 0;
}

.save-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.journey-card {
  display: grid;
  gap: 10px;
  margin-bottom: 12px;
  padding: 12px;
  border: 2px solid rgba(75, 57, 79, 0.18);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 253, 248, 0.9), rgba(255, 226, 235, 0.42)),
    repeating-linear-gradient(90deg, rgba(245, 201, 98, 0.12), rgba(245, 201, 98, 0.12) 1px, transparent 1px, transparent 10px);
}

.journey-card-head {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.journey-card-head strong {
  color: #453044;
}

.journey-card-head span,
.journey-stat span {
  color: var(--muted);
  font-size: 0.86rem;
  font-weight: 800;
}

.journey-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.journey-stat {
  display: grid;
  gap: 3px;
  min-width: 0;
  padding: 8px;
  border: 2px solid rgba(75, 57, 79, 0.12);
  border-radius: 8px;
  background: rgba(255, 253, 248, 0.76);
}

.journey-stat strong {
  min-width: 0;
  overflow-wrap: anywhere;
}

.modal-copy {
  margin: 0 0 12px;
  color: var(--muted);
  line-height: 1.45;
}

.feature-body {
  display: grid;
  gap: 12px;
}

.feature-list {
  display: grid;
  gap: 8px;
}

.feature-row {
  border: 2px solid rgba(75, 57, 79, 0.18);
  border-radius: 8px;
  padding: 10px;
  background: rgba(255, 253, 248, 0.72);
}

.feature-row strong {
  display: block;
  margin-bottom: 4px;
}

.feature-row p {
  margin: 0;
  color: var(--muted);
  line-height: 1.42;
}

.pet-actions,
.settings-grid {
  display: grid;
  gap: 8px;
}

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

.setting-row {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
}

.setting-row input[type="range"] {
  width: 100%;
}

.setting-row input[type="checkbox"] {
  width: 20px;
  height: 20px;
}

.cloud-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) auto;
  gap: 8px;
  margin-bottom: 10px;
}

.cloud-form input {
  min-width: 0;
  border: 2px solid rgba(75, 57, 79, 0.35);
  border-radius: 8px;
  padding: 0.62rem 0.75rem;
  background: #fffdf8;
  color: var(--ink);
  font: inherit;
}

.file-button input {
  display: none;
}

.hidden {
  display: none;
}

@media (max-width: 860px) {
  .title-screen {
    grid-template-columns: 1fr;
    align-content: center;
  }

  .title-art {
    min-height: auto;
  }

  .shell {
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .panel {
    grid-template-columns: 1fr 1fr;
  }

  .touch-controls {
    display: flex;
  }
}

@media (max-width: 560px) {
  .topbar {
    align-items: start;
    flex-direction: column;
  }

  .screen-frame {
    aspect-ratio: 5 / 3.4;
  }

  .panel {
    grid-template-columns: 1fr;
  }

  .dialogue {
    left: 8px;
    right: 8px;
    bottom: 8px;
    min-height: 124px;
  }

  .cloud-form {
    grid-template-columns: 1fr;
  }

  .pet-actions,
  .setting-row,
  .journey-grid,
  .journey-card-head {
    grid-template-columns: 1fr;
  }

  .journey-card-head {
    display: grid;
  }
}
