:root {
  --bg: #0f1220;
  --panel: #181d31;
  --panel-2: #202744;
  --text: #eef2ff;
  --muted: #aeb7d7;
  --accent: #80c4ff;
  --accent-2: #9ef0b4;
  --border: rgba(255,255,255,.09);
  --shadow: 0 18px 40px rgba(0,0,0,.28);
  --radius: 20px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background:
    radial-gradient(circle at top, rgba(128,196,255,.12), transparent 28%),
    linear-gradient(180deg, #0b0e18 0%, #101426 100%);
  color: var(--text);
}

.page {
  width: min(1200px, calc(100vw - 32px));
  margin: 28px auto 52px;
}

.card {
  background: linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.02));
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  border-radius: var(--radius);
  padding: 22px;
  backdrop-filter: blur(10px);
}

.hero {
  display: grid;
  grid-template-columns: 1.4fr .8fr;
  gap: 20px;
  align-items: center;
  position: relative;
  z-index: 20;
  overflow: visible;
  isolation: isolate;
}

.eyebrow {
  margin: 0 0 8px;
  color: var(--accent);
  text-transform: uppercase;
  letter-spacing: .08em;
  font-size: .8rem;
  font-weight: 700;
}

h1, h2, h3 { margin: 0 0 12px; }
h1 { font-size: clamp(2rem, 4vw, 3rem); line-height: 1.06; }
h2 { font-size: 1.25rem; }
h3 { font-size: 1rem; }
.lead { color: var(--muted); font-size: 1.02rem; max-width: 62ch; }

.hero-badges, .preset-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}
.hero-badges {
  position: relative;
  z-index: 2;
  margin-left: auto;
  justify-content: flex-end;
}
.badge, .preset-btn {
  border-radius: 999px;
  border: 1px solid var(--border);
  padding: 10px 14px;
  background: rgba(255,255,255,.05);
  color: var(--text);
}
.lang-picker {
  position: relative;
  z-index: 3;
}
.lang-picker-trigger {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: 156px;
  padding: 10px 14px;
  border-radius: 999px;
  background: rgba(255,255,255,.05);
}
.lang-picker-trigger:hover,
.lang-picker-trigger:focus-visible,
.lang-picker.open .lang-picker-trigger {
  border-color: rgba(128,196,255,.45);
  background: rgba(128,196,255,.12);
}
.lang-picker-flag {
  width: 22px;
  height: 16px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,.14);
  object-fit: cover;
  box-shadow: 0 1px 6px rgba(0,0,0,.24);
}
.lang-picker-label {
  font-weight: 700;
}
.lang-picker-caret {
  width: 10px;
  height: 10px;
  margin-left: auto;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg) translateY(-2px);
  opacity: .75;
}
.lang-picker-menu {
  position: absolute;
  top: calc(100% + 10px);
  right: 0;
  min-width: 220px;
  padding: 10px;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(20,26,45,.98), rgba(15,19,33,.98));
  box-shadow: 0 24px 44px rgba(0,0,0,.34);
  z-index: 200;
}
.lang-picker-option {
  width: 100%;
  display: grid;
  grid-template-columns: 24px 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  text-align: left;
}
.lang-picker-option + .lang-picker-option {
  margin-top: 8px;
}
.lang-picker-option:hover,
.lang-picker-option:focus-visible {
  border-color: rgba(128,196,255,.45);
  background: rgba(128,196,255,.12);
}
.lang-picker-option.active {
  border-color: rgba(128,196,255,.5);
  background: linear-gradient(180deg, rgba(128,196,255,.24), rgba(128,196,255,.1));
}
.lang-picker-option-copy {
  display: grid;
  gap: 2px;
}
.lang-picker-option-name {
  font-weight: 700;
}
.lang-picker-option-meta {
  font-size: .82rem;
  color: var(--muted);
}
.lang-picker-option-short {
  font-size: .78rem;
  font-weight: 800;
  letter-spacing: .06em;
  color: var(--accent);
}
.preset-btn {
  cursor: pointer;
  transition: transform .15s ease, border-color .15s ease, background .15s ease;
}
.preset-btn:hover, .preset-btn:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(128,196,255,.45);
  background: rgba(128,196,255,.12);
}

.presets, .result-card, .project-warning, .notes, .sources-panel { margin-top: 18px; }
.presets {
  position: relative;
  z-index: 1;
}
.form-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 18px;
  position: relative;
  z-index: 6;
}
.form-grid > section {
  position: relative;
  z-index: 1;
  background: rgba(255,255,255,.02);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 18px;
}

.form-grid > section.memo-picker-open {
  z-index: 30;
}

.field { margin-bottom: 16px; }
.field:last-child { margin-bottom: 0; }
.field.hidden { display: none; }
.field-control-group {
  display: grid;
  gap: 10px;
}
.field-preview-only .field-control-group {
  display: none;
}
label {
  display: inline-block;
  margin-bottom: 8px;
  font-size: .95rem;
  font-weight: 600;
}
input[type="search"],
input[type="number"],
input[type="text"],
select,
textarea {
  width: 100%;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  color: var(--text);
  padding: 12px 14px;
  font: inherit;
}
select { min-height: 48px; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}
textarea {
  resize: vertical;
  min-height: 110px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 1.2rem;
  letter-spacing: .08em;
}

.inline-row, .stack-on-mobile, .result-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}
.inline-row > *:first-child { flex: 1; }
.subtype-wrap { min-width: 220px; }
.hidden { display: none; }
.small-field input { max-width: 150px; }
.checkbox-inline,
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0;
}
.checkbox-inline input,
.toggle input { width: auto; }
.toggle-field { padding-top: 8px; }
.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: .92rem;
}
.entity-preview {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 62px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(8, 12, 22, .38);
}
.entity-preview.hidden {
  display: none;
}
.entity-preview-visual {
  width: 44px;
  height: 44px;
  flex: 0 0 auto;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.08);
  background: linear-gradient(180deg, rgba(255,255,255,.08), rgba(255,255,255,.02));
  object-fit: contain;
  image-rendering: pixelated;
}
.entity-preview-copy {
  min-width: 0;
  display: grid;
  gap: 2px;
}
.entity-preview-label {
  font-size: .76rem;
  font-weight: 800;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--accent);
}
.entity-preview-name {
  font-weight: 700;
  line-height: 1.2;
}
.entity-preview-meta {
  color: var(--muted);
  font-size: .88rem;
  line-height: 1.3;
}
.summary-box {
  margin-top: 18px;
  padding: 16px;
  border-radius: 16px;
  background: rgba(158, 240, 180, .08);
  border: 1px solid rgba(158, 240, 180, .18);
}
.summary-box p { margin: 0; color: #eafbf0; }

.advanced-panel {
  margin-top: 8px;
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px 14px;
  background: rgba(255,255,255,.02);
}
.advanced-panel summary {
  cursor: pointer;
  font-weight: 700;
  color: var(--accent);
}
.advanced-panel[open] summary { margin-bottom: 14px; }

.result-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  margin-bottom: 14px;
}
button {
  border: 1px solid var(--border);
  background: rgba(255,255,255,.05);
  color: var(--text);
  padding: 11px 15px;
  border-radius: 12px;
  font: inherit;
  cursor: pointer;
}
button.primary {
  background: linear-gradient(180deg, #7fc4ff, #5ab2ff);
  color: #07131f;
  border-color: rgba(127,196,255,.65);
  font-weight: 800;
}
button:hover, button:focus-visible {
  border-color: rgba(255,255,255,.22);
}
.compact-output input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.notes ul {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
}
.notes li + li { margin-top: 8px; }
.project-warning {
  background:
    linear-gradient(180deg, rgba(255,255,255,.03), rgba(255,255,255,.02)),
    linear-gradient(135deg, rgba(255, 184, 77, .08), rgba(255, 107, 107, .08));
  border-color: rgba(255, 196, 92, .22);
}
.project-warning .lead {
  max-width: 70ch;
}
.sources-panel {
  padding: 0;
  overflow: hidden;
}
.sources-panel summary {
  cursor: pointer;
  padding: 18px 22px;
  font-weight: 800;
  color: var(--accent);
  list-style: none;
}
.sources-panel summary::-webkit-details-marker {
  display: none;
}
.sources-panel summary::after {
  content: "+";
  float: right;
  color: var(--text);
  font-size: 1.1rem;
}
.sources-panel[open] summary::after {
  content: "−";
}
.sources-panel-content {
  padding: 0 22px 22px;
  display: grid;
  gap: 18px;
}
.sources-block h3 {
  margin-bottom: 8px;
}
.sources-block p {
  margin: 0;
  color: var(--muted);
}
.sources-block p + p {
  margin-top: 8px;
}
.source-list {
  margin: 0;
  padding-left: 1.2rem;
  color: var(--muted);
}
.source-list li + li {
  margin-top: 8px;
}
.source-list a {
  color: var(--accent);
  text-decoration: none;
}
.source-list a:hover,
.source-list a:focus-visible {
  text-decoration: underline;
}
.footer {
  padding: 18px 8px 0;
  color: var(--muted);
  font-size: .92rem;
}

@media (max-width: 1024px) {
  .form-grid { grid-template-columns: 1fr; }
  .hero { grid-template-columns: 1fr; }
  .memo-spotlight { grid-template-columns: 1fr; }
}

@media (max-width: 720px) {
  .page { width: min(100vw - 20px, 1200px); margin-top: 14px; }
  .card { padding: 18px; }
  .result-header, .result-actions, .stack-on-mobile, .inline-row {
    flex-direction: column;
    align-items: stretch;
  }
  .subtype-wrap { min-width: 0; width: 100%; }
  .memo-visuals-header,
  .memo-gallery-grid {
    grid-template-columns: 1fr;
  }
  .source-link {
    justify-self: start;
  }
  .memo-picker-panel {
    width: min(100vw - 40px, 560px);
    max-width: min(100vw - 40px, 560px);
    grid-template-columns: 1fr;
  }
  .memo-picker-options {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .memo-picker-options {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

.memo-selector {
  padding: 14px;
  border-radius: 16px;
  background: rgba(128,196,255,.08);
  border: 1px solid rgba(128,196,255,.18);
  position: relative;
  z-index: 12;
}
.memo-selector.hidden { display: none; }

.memo-picker {
  position: relative;
  z-index: 20;
}

.memo-picker-trigger {
  width: 100%;
  min-height: 58px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: var(--panel-2);
  text-align: left;
}

.memo-picker-trigger[aria-expanded="true"] {
  border-color: rgba(128,196,255,.45);
  box-shadow: 0 0 0 1px rgba(128,196,255,.15);
}

.memo-picker-copy {
  display: grid;
  gap: 4px;
}

.memo-picker-title {
  font-weight: 700;
}

.memo-picker-subtitle {
  color: var(--muted);
  font-size: .88rem;
}

.memo-picker-caret {
  width: 11px;
  height: 11px;
  border-right: 2px solid var(--accent);
  border-bottom: 2px solid var(--accent);
  transform: rotate(45deg) translateY(-2px);
  transition: transform .15s ease;
  flex: 0 0 auto;
}

.memo-picker-trigger[aria-expanded="true"] .memo-picker-caret {
  transform: rotate(-135deg) translateY(-1px);
}

.memo-picker-panel {
  position: absolute;
  top: calc(100% + 10px);
  left: 0;
  z-index: 40;
  width: min(900px, calc(100vw - 48px));
  max-width: calc(100vw - 48px);
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(260px, .9fr);
  gap: 14px;
  align-items: start;
  border-radius: 18px;
  border: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(255,255,255,.04), rgba(255,255,255,.02)),
    #12192b;
  box-shadow: 0 24px 48px rgba(0,0,0,.38);
}

.memo-picker-panel.hidden {
  display: none;
}

.memo-picker-options {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.memo-picker-option {
  min-height: 50px;
  padding: 8px 10px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(255,255,255,.03);
  display: grid;
  gap: 2px;
  justify-items: center;
  align-content: center;
  text-align: center;
}

.memo-picker-option:hover,
.memo-picker-option:focus-visible {
  border-color: rgba(128,196,255,.4);
  background: rgba(128,196,255,.1);
}

.memo-picker-option.active {
  border-color: rgba(158,240,180,.4);
  background: rgba(158,240,180,.1);
  box-shadow: 0 0 0 1px rgba(158,240,180,.1);
}

.memo-picker-option-name {
  font-size: .72rem;
  font-weight: 700;
  color: var(--muted);
}

.memo-picker-option-floor {
  color: var(--text);
  font-size: 1.02rem;
  font-weight: 800;
}

.memo-picker-preview {
  min-height: 100%;
  padding: 14px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.08);
  background: rgba(8, 12, 22, .44);
}

.memo-picker-preview-badge {
  margin: 0 0 8px;
  color: var(--accent);
  font-size: .82rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .06em;
}

.memo-picker-preview-title {
  margin-bottom: 8px;
}

.memo-picker-preview-text {
  margin: 0;
  color: var(--muted);
  min-height: 3.4em;
}

.memo-picker-preview-features {
  margin-top: 10px;
}

.memo-picker-preview .memo-map-card {
  margin-top: 14px;
  min-height: 150px;
}

.memo-visuals {
  margin-top: 18px;
  position: relative;
  z-index: 1;
}

.memo-visuals-header,
.memo-spotlight {
  display: grid;
  gap: 18px;
}

.memo-visuals-header {
  grid-template-columns: 1.2fr auto;
  align-items: start;
}

.source-links {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  justify-content: flex-end;
}

.source-link {
  align-self: center;
  justify-self: end;
  color: var(--accent);
  text-decoration: none;
  font-weight: 700;
}

.source-link:hover,
.source-link:focus-visible {
  text-decoration: underline;
}

.memo-spotlight {
  margin-top: 18px;
  grid-template-columns: minmax(0, 1fr) minmax(280px, .9fr);
  align-items: stretch;
  background: rgba(255,255,255,.03);
  border: 1px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
}

.memo-spotlight-copy {
  padding: 20px;
}

.small-badge {
  display: inline-flex;
  margin-bottom: 12px;
  padding: 7px 11px;
  font-size: .82rem;
}

.memo-gallery-grid {
  margin-top: 18px;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.memo-card {
  overflow: hidden;
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,.03);
  cursor: pointer;
}

.memo-card.active {
  border-color: rgba(128,196,255,.45);
  box-shadow: 0 0 0 1px rgba(128,196,255,.2);
}

.memo-card-body {
  padding: 14px;
}

.memo-card-body h3 {
  margin-bottom: 8px;
}

.memo-card-body p {
  margin: 0;
  color: var(--muted);
}

.memo-card-meta {
  margin-bottom: 8px !important;
  color: var(--accent-2) !important;
  font-size: .9rem;
}

.memo-meta-line {
  margin: 10px 0 0;
  color: var(--muted);
}

.memo-warning {
  margin: 12px 0 0;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid rgba(255, 189, 89, .32);
  background: rgba(255, 189, 89, .12);
  color: #ffe2a8;
  font-size: .92rem;
  line-height: 1.45;
}

.memo-feature-list {
  margin-top: 12px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.memo-feature {
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.1);
  color: var(--text);
  font-size: .82rem;
}

.memo-source-code {
  margin: 14px 0 0;
  padding: 12px 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(10, 14, 24, .8);
  color: var(--accent-2);
  font: 600 .95rem/1.5 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  white-space: pre-wrap;
}

.memo-map {
  --memo-cols: 1;
  --memo-cell-size: 12px;
  display: grid;
  grid-template-columns: repeat(var(--memo-cols), var(--memo-cell-size));
  grid-auto-rows: var(--memo-cell-size);
  gap: 2px;
  padding: 18px;
  align-content: start;
  justify-content: center;
  background:
    linear-gradient(180deg, rgba(255,255,255,.02), rgba(255,255,255,.01)),
    radial-gradient(circle at top, rgba(128,196,255,.12), transparent 36%),
    #111726;
}

.memo-map-large {
  min-height: 320px;
}

.memo-map-card {
  min-height: 180px;
  padding: 14px;
}

.memo-map-empty {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--muted);
  font-weight: 700;
  text-align: center;
  padding: 24px;
}

.memo-tile {
  display: grid;
  place-items: center;
  position: relative;
  border-radius: 3px;
  font-size: calc(var(--memo-cell-size) * .55);
  font-weight: 800;
  line-height: 1;
  cursor: help;
}

.memo-tile::after {
  content: attr(data-tooltip);
  position: absolute;
  left: 50%;
  bottom: calc(100% + 8px);
  transform: translateX(-50%) translateY(4px);
  min-width: max-content;
  max-width: 160px;
  padding: 6px 8px;
  border-radius: 8px;
  background: rgba(7, 10, 18, .96);
  border: 1px solid rgba(255,255,255,.12);
  color: #eef4ff;
  font-size: 11px;
  font-weight: 700;
  line-height: 1.3;
  text-align: center;
  white-space: normal;
  pointer-events: none;
  opacity: 0;
  z-index: 30;
  box-shadow: 0 12px 24px rgba(0,0,0,.28);
  transition: opacity .12s ease, transform .12s ease;
}

.memo-tile::before {
  content: "";
  position: absolute;
  left: 50%;
  bottom: calc(100% + 3px);
  width: 8px;
  height: 8px;
  background: rgba(7, 10, 18, .96);
  border-right: 1px solid rgba(255,255,255,.12);
  border-bottom: 1px solid rgba(255,255,255,.12);
  transform: translateX(-50%) rotate(45deg);
  pointer-events: none;
  opacity: 0;
  z-index: 29;
  transition: opacity .12s ease, transform .12s ease;
}

.memo-tile:hover::after,
.memo-tile:hover::before,
.memo-tile:focus-visible::after,
.memo-tile:focus-visible::before {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.memo-tile-wall {
  background: #0a0d14;
}

.memo-tile-floor {
  background: rgba(240, 244, 255, .1);
}

.memo-tile-water {
  background: #1f7aa4;
}

.memo-tile-stairs {
  background: #c9ced8;
  color: #15202f;
}

.memo-tile-treasure {
  background: #d9a530;
  color: #271600;
}

.memo-tile-luxurychest {
  background: linear-gradient(180deg, #f2d24f, #5bb56c);
  color: #10230f;
}

.memo-tile-player {
  background: #f4d84a;
  color: #2d2600;
}

.memo-tile-key {
  background: #9ca5b3;
  color: #111827;
}

.memo-tile-breakwall {
  background: #3655a8;
  color: #eef2ff;
}

.memo-tile-chestnut {
  background: #9c5b2d;
  color: #fff4e8;
}

.memo-tile-wind {
  background: #2f9f8d;
  color: #041815;
}

.memo-tile-warp {
  background: #d56a2f;
  color: #2f1204;
}
