:root {
  color: #173642;
  background: #bce8ef;
  font-family: "Trebuchet MS", "Segoe UI", sans-serif;
  font-synthesis: none;
  --ink: #173642;
  --paper: #fffdf7;
  --coral: #e85d75;
  --teal: #167f83;
  --gold: #f0b53d;
  --violet: #7457b5;
  --line: rgba(23, 54, 66, .18);
}

* { box-sizing: border-box; }
html, body, #app { width: 100%; min-height: 100%; margin: 0; }
body { min-height: 100dvh; overflow-x: hidden; }
button, input { font: inherit; }
button { color: inherit; cursor: pointer; }
.hidden { display: none !important; }

.welcome-screen {
  position: relative;
  min-height: 100dvh;
  display: grid;
  align-items: center;
  overflow: hidden;
  background: #5ca8cc;
}

.welcome-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  object-position: 65% center;
}

.welcome-shade {
  position: absolute;
  inset: 0;
  background: linear-gradient(90deg, rgba(11, 38, 50, .88) 0%, rgba(11, 38, 50, .62) 42%, rgba(11, 38, 50, .08) 72%);
}

.welcome-copy {
  position: relative;
  z-index: 1;
  width: min(570px, calc(100% - 40px));
  margin-left: clamp(20px, 8vw, 140px);
  padding: 42px 0;
  color: white;
}

.eyebrow {
  display: block;
  color: #ffe08a;
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 1.4px;
  text-transform: uppercase;
}

.welcome-copy h1 {
  margin: 8px 0 16px;
  font-family: Georgia, serif;
  font-size: clamp(60px, 9vw, 126px);
  line-height: .88;
  letter-spacing: 0;
  text-shadow: 0 4px 26px rgba(0, 0, 0, .25);
}

.welcome-copy > p {
  max-width: 520px;
  margin: 0 0 28px;
  font-size: clamp(17px, 2vw, 22px);
  line-height: 1.5;
}

#name-form {
  width: min(100%, 440px);
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

#name-form label {
  font-size: 12px;
  font-weight: 900;
  text-transform: uppercase;
}

#name-form label[for="player-name"] { grid-column: 1; grid-row: 1; }
#name-form label[for="pony-name"] { grid-column: 2; grid-row: 1; }
#player-name { grid-column: 1; grid-row: 2; }
#pony-name { grid-column: 2; grid-row: 2; }

#name-form input {
  min-width: 0;
  height: 52px;
  padding: 0 15px;
  color: var(--ink);
  background: rgba(255, 255, 255, .95);
  border: 2px solid transparent;
  border-radius: 6px;
  outline: none;
}

#name-form input:focus { border-color: #ffe08a; box-shadow: 0 0 0 3px rgba(255, 224, 138, .25); }

.primary-button {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 54px;
  padding: 0 18px;
  color: white;
  background: var(--coral);
  border: 0;
  border-radius: 6px;
  box-shadow: 0 5px 0 #a9344c;
  font-weight: 900;
}

#name-form .primary-button { grid-column: 1 / -1; grid-row: 3; margin-top: 9px; }
.welcome-stats-button {
  grid-column: 1 / -1;
  min-height: 42px;
  color: white;
  background: rgba(8, 35, 46, .42);
  border: 1px solid rgba(255, 255, 255, .55);
  border-radius: 5px;
  font-weight: 900;
}
.install-app-button {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
  padding: 0 15px;
  color: var(--ink);
  background: #ffe08a;
  border: 0;
  border-radius: 5px;
  box-shadow: 0 4px 0 #b78625;
  font-weight: 900;
}
.install-app-button:active { transform: translateY(2px); box-shadow: 0 2px 0 #b78625; }
.primary-button:active { transform: translateY(3px); box-shadow: 0 2px 0 #a9344c; }

.game-screen {
  height: 100dvh;
  min-height: 600px;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  overflow: hidden;
  background: #173642;
}

.game-header {
  z-index: 3;
  min-height: 76px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 20px;
  padding: max(10px, env(safe-area-inset-top)) clamp(14px, 4vw, 52px) 10px;
  color: white;
  background: #12313c;
  border-bottom: 2px solid rgba(255, 255, 255, .12);
}

.identity { display: flex; align-items: center; gap: 10px; min-width: 0; }
.identity div { min-width: 0; }
.identity small, .time-box small, .mission-progress small { display: block; color: #a8dfe3; font-size: 11px; font-weight: 800; }
.identity strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 18px; }
.pony-mark {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  width: 42px;
  height: 42px;
  padding: 0;
  color: var(--ink);
  background: white;
  border: 2px solid #a8dfe3;
  border-radius: 50%;
  box-shadow: 0 3px 0 #071f28;
  font-size: 23px;
}
.pony-mark:active { transform: translateY(2px); box-shadow: 0 1px 0 #071f28; }
.mission-progress { text-align: center; }
#heart-meter { display: flex; gap: 4px; min-height: 22px; justify-content: center; }
.meter-heart {
  color: transparent;
  font-size: 22px;
  line-height: 1;
  -webkit-text-stroke: 1.6px #8aa0a6;
  text-shadow: none;
}
.meter-heart.earned {
  color: #ed526c;
  -webkit-text-stroke: 1px #ff9cad;
  filter: drop-shadow(0 0 5px rgba(255, 112, 136, .55));
}
.time-box { text-align: right; }
.time-box strong { display: block; color: #ffe08a; font-size: 28px; font-variant-numeric: tabular-nums; }

.world-shell { position: relative; width: 100%; min-width: 0; min-height: 0; overflow: hidden; background: #8dd7e4; }
#map-canvas { display: block; width: 100%; height: 100%; object-fit: fill; touch-action: none; }

.map-tools {
  position: absolute;
  top: 14px;
  right: 14px;
  display: flex;
  gap: 8px;
}

.icon-button, .dialog-close {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  padding: 0;
  color: white;
  background: rgba(18, 49, 60, .84);
  border: 1px solid rgba(255, 255, 255, .45);
  border-radius: 50%;
  font-size: 22px;
  font-weight: 900;
  backdrop-filter: blur(8px);
}

.location-prompt {
  position: absolute;
  left: 50%;
  bottom: 18px;
  width: min(560px, calc(100% - 28px));
  min-height: 70px;
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px 12px;
  background: rgba(255, 253, 247, .96);
  border: 1px solid rgba(23, 54, 66, .2);
  border-radius: 8px;
  box-shadow: 0 14px 38px rgba(16, 46, 58, .26);
  transform: translateX(-50%);
}

#location-icon {
  display: grid;
  place-items: center;
  width: 44px;
  height: 44px;
  color: white;
  background: var(--violet);
  border-radius: 50%;
  font-size: 22px;
}

.location-prompt small { display: block; color: #64808a; font-size: 10px; font-weight: 900; text-transform: uppercase; }
.location-prompt strong { font-size: 16px; }
.location-prompt button {
  min-height: 42px;
  padding: 0 14px;
  color: white;
  background: var(--teal);
  border: 0;
  border-radius: 5px;
  font-size: 13px;
  font-weight: 900;
}

.toast {
  position: absolute;
  left: 50%;
  top: 18px;
  padding: 10px 15px;
  color: white;
  background: rgba(18, 49, 60, .9);
  border-radius: 5px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .2);
  transform: translateX(-50%);
  font-weight: 800;
}

.touch-pad {
  display: grid;
  grid-template-columns: repeat(4, 58px) 1fr;
  gap: 8px;
  align-items: center;
  min-height: 86px;
  padding: 10px max(14px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left));
  color: white;
  background: #12313c;
  border-top: 2px solid rgba(255, 255, 255, .12);
}

.touch-pad button {
  width: 58px;
  height: 58px;
  padding: 0;
  color: white;
  background: #2c5963;
  border: 1px solid #78aab1;
  border-radius: 50%;
  box-shadow: 0 4px 0 #091f27;
  font-size: 26px;
  touch-action: none;
}

.touch-pad button.pressed, .touch-pad button:active { transform: translateY(3px); background: var(--teal); box-shadow: 0 1px 0 #091f27; }
.touch-pad p { margin: 0 0 0 8px; color: #a8dfe3; font-size: 13px; }

dialog {
  color: var(--ink);
  background: var(--paper);
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(5, 24, 31, .4);
}

dialog::backdrop { background: rgba(7, 30, 39, .76); backdrop-filter: blur(6px); }
.event-dialog { width: min(940px, calc(100vw - 24px)); padding: 0; overflow: hidden; }
.event-dialog[open] { display: grid; grid-template-columns: minmax(280px, .9fr) minmax(380px, 1.1fr); }
.dialog-close { position: absolute; z-index: 5; top: 12px; right: 12px; background: rgba(18, 49, 60, .7); }

.event-visual { position: relative; min-height: 520px; overflow: hidden; background: #96cce2; }
.event-visual img { width: 100%; height: 100%; object-fit: cover; object-position: center; transform: scale(1.04); transition: transform .7s ease; }
.event-dialog[open] .event-visual img { transform: scale(1); }
.event-glow { position: absolute; inset: auto 0 0; height: 42%; background: linear-gradient(transparent, rgba(13, 49, 62, .75)); }
.event-place { position: absolute; left: 22px; bottom: 20px; display: flex; align-items: center; gap: 10px; color: white; }
.event-place span { display: grid; place-items: center; width: 42px; height: 42px; background: var(--violet); border-radius: 50%; font-size: 21px; }
.event-place strong { font-size: 19px; }
.event-content { min-width: 0; padding: clamp(28px, 5vw, 54px); align-self: center; }
.event-content .eyebrow { color: var(--teal); }
.event-content h2 { margin: 7px 0 12px; font-family: Georgia, serif; font-size: clamp(30px, 4vw, 47px); line-height: 1.04; letter-spacing: 0; }
.event-content > p { line-height: 1.55; }
.challenge-area { display: grid; gap: 9px; margin-top: 22px; }
.challenge-area button {
  min-height: 48px;
  padding: 10px 14px;
  text-align: left;
  background: white;
  border: 2px solid #c9d7d8;
  border-radius: 6px;
  font-weight: 800;
}
.challenge-area button:hover { border-color: var(--teal); background: #f0fbf9; }
.challenge-area button.correct { color: white; background: var(--teal); border-color: var(--teal); }
.challenge-area button.wrong { color: white; background: var(--coral); border-color: var(--coral); }
.event-feedback { min-height: 24px; margin-bottom: 0; color: var(--coral); font-weight: 900; }
.event-feedback.success { color: var(--teal); }

.sequence-board, .memory-board {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}
.sequence-board button, .memory-board button { min-width: 0; text-align: center; font-size: 22px; }
.recipe-row { display: flex; flex-wrap: wrap; gap: 8px; min-height: 52px; padding: 8px; background: #edf5f3; border: 2px dashed #a8c0c0; border-radius: 6px; }
.recipe-chip { padding: 7px 9px; color: white; background: var(--violet); border-radius: 4px; font-size: 13px; font-weight: 800; }

.pony-preview-dialog {
  width: min(620px, calc(100vw - 24px));
  padding: 0;
  overflow: hidden;
}
.pony-preview-dialog img {
  display: block;
  width: 100%;
  max-height: 68vh;
  object-fit: cover;
  object-position: center 42%;
}
.pony-preview-dialog > div {
  position: absolute;
  inset: auto 0 0;
  padding: 65px 26px 24px;
  color: white;
  background: linear-gradient(transparent, rgba(10, 38, 49, .94));
}
.pony-preview-dialog .eyebrow { color: #ffe08a; }
.pony-preview-dialog h2 { margin: 4px 0; font-family: Georgia, serif; font-size: 36px; letter-spacing: 0; }
.pony-preview-dialog p { margin: 0; }

.stats-dialog {
  width: min(620px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  padding: 34px;
  overflow-y: auto;
}
.stats-dialog .eyebrow { color: var(--teal); }
.stats-dialog h2 { margin: 6px 0 22px; font-family: Georgia, serif; font-size: 42px; letter-spacing: 0; }
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin-bottom: 24px;
}
.stats-grid > div {
  min-width: 0;
  padding: 13px 9px;
  text-align: center;
  background: #edf5f3;
  border: 1px solid #c8dcda;
  border-radius: 6px;
}
.stats-grid small { display: block; min-height: 28px; color: #58737a; font-size: 10px; font-weight: 900; text-transform: uppercase; }
.stats-grid strong { display: block; color: var(--teal); font-size: 25px; font-variant-numeric: tabular-nums; }
.location-stats { margin-bottom: 22px; }
.location-stats h3, .stats-dialog .ranking h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; }
#location-stats-list { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 16px; }
#location-stats-list > div {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-width: 0;
  padding: 7px 0;
  border-bottom: 1px solid #dfe8e6;
}
#location-stats-list span { display: flex; min-width: 0; align-items: center; gap: 7px; font-size: 13px; }
#location-stats-list i { font-style: normal; }
#location-stats-list strong { color: var(--coral); }
.empty-ranking { color: #718188; list-style: none; }
.danger-button {
  width: 100%;
  min-height: 48px;
  margin-top: 4px;
  color: #a5233c;
  background: #fff0f2;
  border: 2px solid #e9a2ae;
  border-radius: 5px;
  font-weight: 900;
}
.danger-button:hover { color: white; background: #b62d45; border-color: #b62d45; }

.password-dialog {
  width: min(430px, calc(100vw - 24px));
  padding: 32px;
}
.password-dialog .eyebrow { color: var(--teal); }
.password-dialog h2 { margin: 6px 0 10px; font-family: Georgia, serif; font-size: 36px; letter-spacing: 0; }
.password-dialog > p { line-height: 1.5; }
.password-dialog form { display: grid; gap: 9px; margin-top: 20px; }
.password-dialog label { font-size: 12px; font-weight: 900; text-transform: uppercase; }
.password-dialog input {
  min-height: 50px;
  padding: 0 14px;
  border: 2px solid #b9cccd;
  border-radius: 5px;
  outline: none;
}
.password-dialog input:focus { border-color: var(--teal); box-shadow: 0 0 0 3px rgba(22, 127, 131, .16); }
.password-error { min-height: 20px; margin: 0; color: #b62d45; font-size: 13px; font-weight: 900; }

.install-dialog {
  width: min(520px, calc(100vw - 24px));
  padding: 34px;
}
.install-dialog .eyebrow { color: var(--teal); }
.install-dialog h2 { margin: 6px 0 10px; font-family: Georgia, serif; font-size: 36px; letter-spacing: 0; }
.install-dialog > p { line-height: 1.5; }
.install-dialog .primary-button { width: 100%; margin-top: 18px; }
.install-status { display: grid; gap: 8px; margin-top: 18px; }
.install-status > div {
  display: grid;
  grid-template-columns: 30px 1fr;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid #c9d9d8;
  border-radius: 6px;
  background: #f5faf9;
}
.install-status > div > span {
  display: grid;
  width: 28px;
  height: 28px;
  place-items: center;
  border-radius: 50%;
  color: white;
  font-weight: 900;
}
.install-status .ok > span { background: #27835c; }
.install-status .problem > span { background: #b7443d; }
.install-status p { margin: 0; }
.install-status strong, .install-status small { display: block; }
.install-status small { margin-top: 2px; overflow-wrap: anywhere; color: #5f6d6c; }

.finish-dialog { width: min(480px, calc(100vw - 24px)); padding: 34px; text-align: center; }
.finish-star { color: var(--gold); font-size: 64px; filter: drop-shadow(0 5px 0 #e36c61); }
.finish-dialog .eyebrow { color: var(--teal); }
.finish-dialog h2 { margin: 6px 0; font-family: Georgia, serif; font-size: 46px; letter-spacing: 0; }
.finish-dialog > p { line-height: 1.5; }
.result-time { margin: 20px 0; padding: 14px; color: white; background: #173642; border-radius: 6px; }
.result-time small { display: block; color: #a8dfe3; font-size: 10px; font-weight: 900; text-transform: uppercase; }
.result-time strong { color: #ffe08a; font-size: 36px; font-variant-numeric: tabular-nums; }
.ranking { margin: 0 0 22px; text-align: left; }
.ranking h3 { margin: 0 0 8px; font-size: 13px; text-transform: uppercase; }
.ranking ol { margin: 0; padding-left: 28px; }
.ranking li { padding: 5px; border-bottom: 1px solid #dfe8e6; font-size: 14px; }
.ranking li::marker { color: var(--coral); font-weight: 900; }
.finish-dialog .primary-button { width: 100%; }
.text-button { margin-top: 12px; padding: 8px; color: var(--teal); background: transparent; border: 0; font-weight: 900; text-decoration: underline; }

@media (max-width: 720px) {
  .welcome-screen { align-items: end; }
  .welcome-art { object-position: 62% 20%; }
  .welcome-shade { background: linear-gradient(0deg, rgba(11, 38, 50, .94) 0%, rgba(11, 38, 50, .55) 56%, rgba(11, 38, 50, .08) 82%); }
  .welcome-copy { width: calc(100% - 32px); margin: 0 auto; padding: 34px 0 28px; }
  .welcome-copy h1 { font-size: clamp(55px, 19vw, 92px); }
  .welcome-copy > p { margin-bottom: 20px; font-size: 16px; }
  #name-form { grid-template-columns: 1fr; }
  #name-form label[for="player-name"],
  #name-form label[for="pony-name"],
  #player-name,
  #pony-name,
  #name-form .primary-button,
  .welcome-stats-button,
  .install-app-button { grid-column: 1; grid-row: auto; }
  .game-header { gap: 8px; padding-left: 10px; padding-right: 10px; }
  .pony-mark { width: 36px; height: 36px; font-size: 19px; }
  .identity strong { font-size: 14px; }
  .time-box strong { font-size: 22px; }
  .meter-heart { font-size: 17px; }
  .touch-pad { grid-template-columns: repeat(4, 1fr); }
  .touch-pad button { width: 52px; height: 52px; justify-self: center; }
  .touch-pad p { display: none; }
  .location-prompt { bottom: 10px; grid-template-columns: auto 1fr; }
  .location-prompt button { grid-column: 1 / -1; }
  .event-dialog[open] { display: block; max-height: calc(100dvh - 20px); overflow-y: auto; }
  .event-visual { min-height: 280px; height: 36vh; }
  .event-content { padding: 25px 20px 30px; }
  .event-content h2 { font-size: 32px; }
  .stats-dialog { padding: 28px 20px; }
  .stats-dialog h2 { font-size: 34px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  #location-stats-list { grid-template-columns: 1fr; }
}

@media (orientation: portrait) {
  .world-shell {
    background: #83bfe0 url("assets/portrait-clouds.jpg") center / cover no-repeat;
  }
  #map-canvas {
    position: absolute;
    top: 50%;
    left: 0;
    width: 100%;
    height: auto;
    aspect-ratio: 8 / 5;
    transform: translateY(-50%);
    box-shadow: 0 0 28px rgba(30, 82, 100, .24);
  }
}

@media (max-height: 680px) and (orientation: landscape) {
  .game-header { min-height: 60px; padding-top: 6px; padding-bottom: 6px; }
  .touch-pad { min-height: 68px; padding-top: 6px; padding-bottom: 6px; }
  .touch-pad button { width: 48px; height: 48px; }
  .event-visual { min-height: 400px; }
}
