:root {
  color-scheme: dark;
  --ink: #f4ead6;
  --muted: #b7a98f;
  --gold: #cda65a;
  --gold-dark: #6e5126;
  --wood: #2b2018;
  --panel: #17130f;
  --phone: #242321;
  --phone-edge: #090908;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: #100e0c; }

body {
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  font-family: Inter, system-ui, sans-serif;
  background:
    radial-gradient(circle at 22% 18%, rgba(149, 103, 43, .18), transparent 30rem),
    linear-gradient(rgba(15, 12, 9, .91), rgba(15, 12, 9, .96)),
    repeating-linear-gradient(87deg, #3a2819 0 3px, #22170f 3px 18px, #422d1b 18px 20px);
}

body::before {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: .22;
  background-image: url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)' opacity='.2'/%3E%3C/svg%3E");
}

button, a, canvas { -webkit-tap-highlight-color: transparent; }

.page-shell {
  position: relative;
  z-index: 1;
  width: min(1170px, calc(100% - 32px));
  min-height: calc(100vh - 52px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) 462px;
  align-items: center;
  gap: clamp(40px, 8vw, 110px);
  padding: 42px 0 24px;
}

.intro { max-width: 510px; }
.eyebrow {
  margin: 0 0 14px;
  color: var(--gold);
  font-size: .76rem;
  font-weight: 650;
  letter-spacing: .25em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  color: #f3dfb9;
  font-family: "Cormorant Garamond", Georgia, serif;
  font-size: clamp(4.5rem, 10vw, 8.2rem);
  font-weight: 600;
  line-height: .68;
  letter-spacing: -.055em;
  text-shadow: 0 3px 24px rgba(0, 0, 0, .6);
}

h1 em {
  display: inline-block;
  margin-left: .3em;
  color: var(--gold);
  font-weight: 700;
}

.lead {
  max-width: 440px;
  margin: 42px 0 30px;
  color: #d9ccb6;
  font-size: clamp(1rem, 2vw, 1.2rem);
  line-height: 1.65;
}

.desktop-help {
  padding: 18px 0;
  border-top: 1px solid rgba(205, 166, 90, .28);
  border-bottom: 1px solid rgba(205, 166, 90, .28);
}

.help-title { margin: 0 0 12px; color: var(--muted); font-size: .75rem; text-transform: uppercase; letter-spacing: .12em; }
.shortcut-list { display: flex; flex-wrap: wrap; gap: 10px 18px; color: #cabda8; font-size: .8rem; }
.shortcut-list span { display: flex; align-items: center; gap: 5px; }
kbd { min-width: 25px; padding: 4px 6px; border: 1px solid #5b4b38; border-radius: 4px; background: #211a13; color: #e7d4b0; font: inherit; text-align: center; box-shadow: inset 0 -2px #0e0b09; }
.runtime-note { max-width: 450px; margin: 18px 0 0; color: #817765; font-size: .72rem; line-height: 1.55; }

.phone {
  position: relative;
  width: min(100%, 462px);
  height: min(920px, calc(100dvh - 84px));
  min-height: 620px;
  justify-self: center;
  padding: 24px 25px 20px;
  display: flex;
  flex-direction: column;
  border: 1px solid #47443f;
  border-radius: 42px;
  background: linear-gradient(145deg, #343330, var(--phone) 46%, #171716);
  box-shadow: 0 40px 80px rgba(0, 0, 0, .55), inset 2px 2px 1px rgba(255,255,255,.08), inset -3px -4px 2px var(--phone-edge);
}

.phone:fullscreen { width: min(100vw, 590px); height: 100dvh; min-height: 100dvh; overflow: auto; border-radius: 0; margin: auto; }

.phone.large-text {
  position: fixed;
  z-index: 12;
  inset: 0;
  width: 590px;
  height: 100dvh;
  min-height: 620px;
  max-height: 100vh;
  margin: auto;
  overflow: auto;
  box-shadow: 0 0 0 100vmax rgba(8, 6, 4, .88), 0 30px 100px #000;
}

.speaker { height: 12px; margin-bottom: 15px; display: flex; align-items: center; justify-content: center; gap: 7px; }
.speaker span { width: 5px; height: 5px; border-radius: 50%; background: #0a0a09; box-shadow: inset 1px 1px 1px #000, 0 1px rgba(255,255,255,.08); }

.game-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 1px 12px;
}
.game-nav-tools,
.game-language-switcher,
.hero-tools { display: flex; align-items: center; gap: 5px; }
.game-nav-tools { min-width: 0; }
.game-language-switcher { padding: 2px; border: 1px solid #514b40; border-radius: 8px; background: #191816; }
.font-picker { display: grid; gap: 4px; color: #aaa297; font-size: .62rem; letter-spacing: .04em; text-transform: uppercase; }
.font-picker select,
.hero-tools button,
.toolbar-control,
.game-language-option {
  min-height: 34px;
  border: 1px solid #514b40;
  border-radius: 8px;
  background: #191816;
  color: #e0d7c8;
  font: 600 .68rem Inter, system-ui, sans-serif;
}
.font-picker select { max-width: 158px; padding: 0 28px 0 9px; color-scheme: dark; }
.hero-tools button { padding: 0 8px; cursor: pointer; }
.hero-tools button:disabled { opacity: .38; cursor: wait; }
.hero-tools button:not(:disabled):active { color: var(--gold); transform: translateY(1px); }
.toolbar-control {
  display: inline-flex;
  align-items: center;
  padding: 0 9px;
  color: #e0d7c8;
  text-decoration: none;
  white-space: nowrap;
}
.toolbar-control:hover { color: var(--gold); }
.toolbar-control:focus-visible,
.game-language-option:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.game-language-option {
  min-width: 34px;
  padding: 0 7px;
  border: 0;
  background: transparent;
  color: #aaa297;
  cursor: pointer;
}
.game-language-option[aria-pressed="true"] { background: var(--gold); color: #17130f; }

.screen-frame {
  flex: 1 1 auto;
  min-height: 314px;
  width: 100%;
  padding: 12px;
  border: 1px solid #050504;
  border-radius: 13px;
  background: #0b0b0a;
  box-shadow: inset 0 0 0 2px #35342f, 0 1px rgba(255,255,255,.06);
}

#screen-area {
  width: 100%;
  height: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #f1ead8;
  color: #3b3020;
  border-radius: 4px;
}

#screen { width: 100%; height: 100%; display: flex; align-items: center; justify-content: center; overflow: hidden; }
#screen canvas {
  flex: none;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  background: #fff;
  filter: contrast(1.08);
}
html[data-game-font="modern"] #screen canvas { image-rendering: auto; }
#screen:focus { outline: none; }
#loading { padding: 18px; color: #4c3c25; font-family: Georgia, serif; font-size: 1rem; text-align: center; line-height: 1.4; }

.native-editor {
  box-sizing: border-box;
  width: 100%;
  min-height: 100%;
  padding: 38px 34px 28px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 18px;
  background: #f4eedf;
  color: #211a12;
  font: 16px/1.3 Georgia, serif;
}
.native-editor h2 { margin: 0 0 4px; color: #392a1a; font-size: 25px; text-align: center; }
.native-editor label { display: grid; gap: 6px; font-weight: 700; }
.native-editor input { min-width: 0; padding: 10px 12px; border: 2px solid #75572f; border-radius: 5px; background: #fffdf7; color: #17110b; font: 18px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; }
.native-editor input:focus { outline: 3px solid rgba(164, 117, 49, .3); }
.native-editor-actions { display: flex; justify-content: center; gap: 10px; }
.native-editor-actions button { padding: 8px 18px; border: 1px solid #5b4021; border-radius: 5px; background: #7a572d; color: white; font-weight: 700; cursor: pointer; }

.brandline { height: 36px; display: flex; align-items: center; justify-content: space-between; color: #8e8980; font-size: .63rem; letter-spacing: .1em; text-transform: uppercase; }
.brandline span { color: var(--gold); font-family: Georgia, serif; font-size: .9rem; font-weight: bold; }
.brandline i { font-style: normal; }

.key-grid { display: grid; gap: 8px; }
.navigation-grid { grid-template-columns: repeat(3, 1fr); grid-template-rows: repeat(3, 48px); }

.key {
  touch-action: none;
  user-select: none;
  border: 1px solid #484641;
  border-radius: 14px;
  background: linear-gradient(#373632, #20201e);
  color: #ddd5c8;
  font: 650 .88rem Inter, sans-serif;
  cursor: pointer;
  box-shadow: 0 3px 5px rgba(0,0,0,.5), inset 0 1px rgba(255,255,255,.08);
  transition: transform 70ms ease, background 70ms ease;
}
.key.active { transform: translateY(2px); background: linear-gradient(#1b1a18, #292824); box-shadow: 0 1px 2px #000; color: var(--gold); }
.soft-key { border-radius: 9px 9px 17px 17px; color: #bcb4a8; font-size: .67rem; }
.arrow-key { color: #d8c39a; font-size: 1rem; }
.ok-key { border-color: #775d31; border-radius: 50%; background: radial-gradient(circle at 45% 35%, #a78043, #5a4324); color: white; }
.utility-key { font-size: .9rem; color: #8f897f; }
.text-zoom-key { font-family: Georgia, serif; font-weight: 700; letter-spacing: -.05em; }

footer { position: relative; z-index: 1; padding: 0 16px 18px; color: #5f574c; font-size: .64rem; text-align: center; }

#runtime-alert {
  position: fixed;
  z-index: 20;
  inset: 0;
  padding: 24px;
  place-items: center;
  background: rgba(8, 6, 4, .82);
}
#runtime-alert:not([hidden]) { display: grid; }
#runtime-alert > div { width: min(420px, 100%); padding: 24px; border: 1px solid var(--gold-dark); border-radius: 12px; background: #211a13; box-shadow: 0 20px 70px #000; }
#runtime-alert strong { color: var(--gold); font-family: Georgia, serif; font-size: 1.35rem; }
#runtime-alert .message { color: #d9ccb6; font-size: .85rem; line-height: 1.5; }
#runtime-alert button { padding: 8px 14px; border: 1px solid #65502f; border-radius: 6px; background: #302519; color: var(--ink); cursor: pointer; }

.hero-picker {
  position: fixed;
  z-index: 30;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 20px;
  background: rgba(8, 7, 5, .84);
  backdrop-filter: blur(5px);
}
.hero-picker-card { width: min(390px, 100%); padding: 25px; border: 1px solid var(--gold-dark); border-radius: 16px; background: #211b14; box-shadow: 0 24px 80px #000; text-align: center; }
.hero-picker-card h2 { margin: 0 0 9px; color: #ecd7ae; font: 700 1.45rem Georgia, serif; }
.hero-picker-card p { margin: 0 0 20px; color: #bdb19f; font-size: .82rem; line-height: 1.5; }
.hero-file-button,
.hero-cancel { display: block; width: 100%; min-height: 44px; border-radius: 9px; font: 700 .84rem Inter, system-ui, sans-serif; cursor: pointer; }
.hero-file-button { padding: 13px; background: #8a6432; color: #fff; }
.hero-file-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.hero-cancel { margin-top: 9px; border: 1px solid #554b3e; background: #181512; color: #c9bead; }
.game-toast { position: fixed; z-index: 40; left: 50%; bottom: 24px; translate: -50% 15px; padding: 11px 17px; border: 1px solid #84652f; border-radius: 999px; background: #1d1811; color: #f5e5c6; box-shadow: 0 8px 35px #000; font-size: .8rem; opacity: 0; transition: opacity .18s, translate .18s; }
.game-toast.visible { translate: -50% 0; opacity: 1; }

@media (max-width: 900px) {
  html, body { min-height: 100%; background: #171716; }
  body::before, .intro, footer { display: none; }
  .page-shell { width: 100%; min-height: 100dvh; display: block; padding: 0; }
  .phone,
  .phone.large-text,
  .phone:fullscreen {
    position: relative;
    inset: auto;
    width: 100%;
    max-width: none;
    height: 100dvh;
    min-height: 100dvh;
    max-height: none;
    margin: 0 auto;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(10px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    overflow: visible;
    border: 0;
    border-radius: 0;
    background: linear-gradient(#292825, #181817);
    box-shadow: none;
  }
  .speaker { display: none; }
  .game-toolbar { align-items: center; margin: 0 0 8px; }
  .hero-tools button,
  .toolbar-control,
  .game-language-option { min-height: 44px; padding-inline: 7px; font-size: .62rem; }
  .game-language-option { min-width: 44px; }
  .screen-frame,
  .phone.large-text .screen-frame,
  .phone:fullscreen .screen-frame { width: 100%; min-height: 280px; padding: 6px; margin: 0; border-radius: 10px; }
  #screen canvas,
  .phone.large-text #screen canvas,
  .phone:fullscreen #screen canvas { width: 100%; height: 100%; }
  .native-editor,
  .phone.large-text .native-editor,
  .phone:fullscreen .native-editor { width: 100%; min-height: 100%; padding: 20px 18px 16px; gap: 10px; font-size: 13px; }
  .native-editor h2 { font-size: 19px; }
  .native-editor input { padding: 7px 9px; font-size: 16px; }
  .brandline { height: 27px; padding-inline: 4px; }
  .navigation-grid { grid-template-rows: repeat(3, clamp(48px, 7.4dvh, 58px)); gap: 7px; }
  .key { min-height: 44px; }
}

@media (max-width: 340px) {
  .game-toolbar { display: grid; grid-template-columns: 1fr auto; }
  .hero-tools { grid-column: 1 / -1; justify-content: flex-end; }
  .hero-tools button { padding-inline: 5px; font-size: .56rem; }
  .toolbar-control { padding-inline: 5px; }
  .game-language-option { padding-inline: 4px; }
}

@media (max-width: 900px) and (orientation: landscape) {
  .phone { display: grid; grid-template-columns: minmax(300px, 1.35fr) minmax(230px, .8fr); grid-template-rows: auto 1fr; gap: 8px 12px; align-items: stretch; }
  .game-toolbar { grid-column: 1 / -1; margin: 0; }
  .screen-frame { grid-column: 1; grid-row: 2; }
  .brandline { display: none; }
  .controls-primary { grid-column: 2; grid-row: 2; }
  .navigation-grid { grid-template-rows: repeat(3, min(14dvh, 54px)); }
}

@media (max-height: 720px) and (min-width: 901px) {
  .page-shell { padding-top: 18px; }
  .phone:not(.large-text) { width: 462px; height: calc(100dvh - 36px); min-height: 0; padding: 18px 25px 14px; }
  .navigation-grid { grid-template-rows: repeat(3, 40px); }
  .brandline { height: 29px; }
}

.save-transfer-dialog {
  width: min(720px, calc(100vw - 24px)); max-width: none; max-height: calc(100dvh - 24px); padding: 0; overflow: auto;
  border: 1px solid var(--gold-dark); border-radius: 16px; background: #211b14; color: #e0d7c8; box-shadow: 0 24px 80px #000;
}
.save-transfer-dialog::backdrop { background: rgba(8, 7, 5, .88); backdrop-filter: blur(5px); }
.save-transfer-card { padding: 22px; }
.save-transfer-card header { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; }
.save-transfer-card h2, .save-transfer-card h3 { margin: 0; color: #ecd7ae; font-family: Georgia, serif; }
.save-transfer-card header p { margin: 6px 0 18px; color: #bdb19f; font-size: .78rem; line-height: 1.45; }
.save-transfer-card label { display: block; margin: 10px 0 6px; color: #cfc3af; font-size: .76rem; font-weight: 700; }
.save-close { flex: none; width: 44px; min-height: 44px; padding: 0; font-size: 1.5rem; }
.save-transfer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.save-transfer-grid section { min-width: 0; padding: 16px; border: 1px solid #514b40; border-radius: 12px; background: #191816; }
.save-transfer-dialog textarea { box-sizing: border-box; width: 100%; min-height: 110px; resize: vertical; padding: 10px; border: 1px solid #655b4d; border-radius: 8px; background: #0e0d0c; color: #f1e5cf; font: .7rem/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; overflow-wrap: anywhere; }
.save-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.save-transfer-dialog button, .save-image-button { box-sizing: border-box; min-height: 44px; padding: 0 13px; border: 1px solid #655b4d; border-radius: 8px; background: #29241e; color: #e0d7c8; font: 700 .74rem Inter, system-ui, sans-serif; cursor: pointer; }
.save-transfer-dialog button:disabled { opacity: .45; cursor: default; }
.save-image-button { display: inline-flex !important; align-items: center; margin: 0 !important; }
.save-image-button input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.save-transfer-dialog .save-primary { border-color: #9b7540; background: #76562f; color: #fff; }
.save-done { display: block; margin: 16px 0 0 auto; }
.save-qr { display: grid; place-items: center; min-height: 0; margin-top: 12px; }
.save-qr canvas { display: block; width: min(420px, 100%); height: auto; border: 4px solid #fff; }
.save-transfer-dialog.save-qr-expanded { overflow: visible; }
.save-transfer-dialog.save-qr-expanded .save-qr { position: fixed; inset: 0; z-index: 2; margin: 0; padding: 12px; background: #fff; }
.save-transfer-dialog.save-qr-expanded .save-qr canvas { width: min(calc(100vw - 24px), calc(100dvh - 88px)); border: 0; }
.save-transfer-dialog.save-qr-expanded #save-enlarge-qr { position: fixed; right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); z-index: 3; border-color: #17130f; background: #29241e; }
.save-hint, .save-status { margin: 10px 0 0; color: #cbbb9f; font-size: .78rem; line-height: 1.4; }
.save-status.error { color: #ffb5a8; }
#save-camera-preview { width: 100%; max-height: 220px; margin-top: 10px; border-radius: 8px; background: #000; object-fit: cover; }
@media (max-width: 640px) {
  .save-transfer-dialog { width: calc(100vw - 12px); max-height: calc(100dvh - 12px); }
  .save-transfer-card { padding: 14px; }
  .save-transfer-grid { grid-template-columns: 1fr; }
}
@media (max-height: 480px) and (orientation: landscape) {
  .save-transfer-dialog { width: calc(100vw - 12px); max-height: calc(100dvh - 8px); }
  .save-transfer-card { padding: 10px 14px; }
  .save-transfer-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .save-transfer-grid section { padding: 10px; }
  .save-transfer-dialog textarea { min-height: 72px; }
  .save-qr canvas { width: min(260px, 100%); }
}
