:root {
  color-scheme: dark;
  --bg: #071113;
  --bg-soft: #0b191b;
  --panel: rgba(13, 31, 33, .94);
  --panel-2: rgba(18, 42, 43, .92);
  --line: rgba(129, 190, 185, .2);
  --line-hot: rgba(106, 229, 213, .55);
  --cyan: #72e2d5;
  --cyan-soft: #a6eee5;
  --amber: #d9a85d;
  --red: #e56f68;
  --text: #e7efec;
  --muted: #8fa5a2;
  --safe-bottom: max(12px, env(safe-area-inset-bottom));
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
body {
  background:
    radial-gradient(circle at 8% -10%, rgba(54, 145, 139, .18), transparent 36%),
    linear-gradient(180deg, #071113, #050b0c 72%);
  -webkit-tap-highlight-color: transparent;
}
button, select, input { font: inherit; }
button { color: inherit; }
button:focus-visible, select:focus-visible { outline: 2px solid var(--cyan); outline-offset: 2px; }

.boot-screen { min-height: 100dvh; display: grid; place-content: center; text-align: center; padding: 24px; }
.boot-mark { color: var(--cyan-soft); font-size: clamp(28px, 8vw, 48px); letter-spacing: .18em; font-weight: 800; }
.boot-screen p { color: var(--muted); font-size: 12px; letter-spacing: .25em; }
.boot-line { width: min(300px, 72vw); height: 2px; background: rgba(114,226,213,.12); overflow: hidden; margin: 26px auto 12px; }
.boot-line span { display: block; width: 36%; height: 100%; background: var(--cyan); animation: scan 1.2s ease-in-out infinite; }
@keyframes scan { from { transform: translateX(-110%); } to { transform: translateX(380%); } }

.app-shell { height: 100dvh; width: 100%; max-width: 1600px; margin: 0 auto; overflow: hidden; }
.topbar { height: 64px; display: grid; grid-template-columns: minmax(190px, .8fr) minmax(420px, 2fr) auto; align-items: center; gap: 14px; padding: 8px 18px; border-bottom: 1px solid var(--line); background: rgba(7,17,19,.94); backdrop-filter: blur(14px); position: relative; z-index: 20; }
.topbar h1 { font-size: 19px; margin: 1px 0 0; letter-spacing: .08em; white-space: nowrap; }
.brand { min-width: 0; }
.eyebrow { margin: 0; color: var(--cyan); font-size: 8px; letter-spacing: .22em; }
.icon-button { width: 38px; height: 38px; border-radius: 10px; border: 1px solid var(--line-hot); background: #0c2021; color: var(--cyan); font-weight: 800; }
.header-actions { display: flex; align-items: center; justify-content: end; gap: 7px; }
.language-switch { height: 38px; display: grid; grid-template-columns: repeat(2, 36px); padding: 3px; border: 1px solid var(--line); border-radius: 10px; background: #08191a; }
.language-switch button { border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 10px; font-weight: 800; cursor: pointer; }
.language-switch button.active { color: #06201e; background: var(--cyan); }

.resource-strip { min-width: 0; height: 46px; display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.resource-strip div { min-width: 0; padding: 6px 12px; background: rgba(8,22,23,.96); }
.resource-strip span { display: block; color: var(--muted); font-size: 9px; margin-bottom: 3px; }
.resource-strip strong { color: var(--cyan-soft); display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.resource-strip div:last-child strong { color: var(--amber); }

.workspace { height: calc(100dvh - 64px); display: grid; grid-template-columns: 82px minmax(0, 1fr); }
.main-view { padding: 16px 18px 28px; min-width: 0; height: 100%; overflow: auto; overscroll-behavior: contain; }
.view-stack { display: grid; gap: 13px; }
.view-stack.two-column { grid-template-columns: minmax(430px, 1.25fr) minmax(330px, .75fr); align-items: start; }
.panel { background: linear-gradient(145deg, rgba(17,40,41,.96), rgba(9,24,25,.96)); border: 1px solid var(--line); border-radius: 16px; overflow: hidden; box-shadow: 0 18px 50px rgba(0,0,0,.2); }
.panel-pad { padding: 12px; }
.section-heading { display: flex; justify-content: space-between; align-items: end; gap: 12px; margin-bottom: 11px; }
.section-heading h2, .section-heading h3 { margin: 0; font-size: 16px; letter-spacing: .04em; }
.section-heading p { margin: 0; color: var(--muted); font-size: 10px; }
.label { color: var(--cyan); font-size: 9px; letter-spacing: .12em; text-transform: uppercase; }
.muted { color: var(--muted); }
.amber { color: var(--amber); }
.danger { color: var(--red); }
.cyan { color: var(--cyan); }

.hero { min-height: calc(100dvh - 96px); position: sticky; top: 0; display: flex; align-items: end; background-size: cover; background-position: center 32%; }
.hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(4,11,12,.05), rgba(5,15,16,.45) 48%, #091819 96%); }
.hero-content { position: relative; z-index: 1; width: 100%; padding: 82px 16px 16px; }
.hero-content h2 { margin: 0 0 5px; font-size: 25px; }
.hero-content p { margin: 0; max-width: 560px; color: #bbcac7; font-size: 12px; line-height: 1.55; }
.production-number { margin: 14px 0 12px; font-size: clamp(34px, 10vw, 58px); line-height: 1; color: var(--cyan-soft); font-weight: 900; letter-spacing: -.04em; text-shadow: 0 0 28px rgba(114,226,213,.22); }
.action-row { display: flex; gap: 8px; flex-wrap: wrap; }
.primary-button, .secondary-button, .danger-button, .tiny-button { border-radius: 11px; border: 1px solid transparent; min-height: 44px; padding: 10px 15px; font-weight: 800; cursor: pointer; transition: .15s ease; }
.primary-button { background: var(--cyan); color: #06201e; flex: 1; }
.primary-button:hover { background: #9cf2e7; }
.secondary-button { background: rgba(16,46,46,.96); border-color: var(--line-hot); color: var(--cyan-soft); }
.danger-button { background: rgba(95,32,31,.55); border-color: rgba(229,111,104,.5); color: #ffb0aa; }
.tiny-button { min-height: 34px; padding: 6px 10px; font-size: 11px; background: #143132; border-color: var(--line); }
button:disabled { opacity: .38; cursor: not-allowed; filter: saturate(.4); }

.metric-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.metric { padding: 11px; border: 1px solid var(--line); background: rgba(6,18,19,.5); border-radius: 11px; }
.metric span { display: block; font-size: 9px; color: var(--muted); margin-bottom: 5px; }
.metric strong { font-size: 14px; }
.reason-list { display: grid; gap: 7px; margin-top: 11px; }
.reason { display: flex; justify-content: space-between; gap: 10px; padding-bottom: 7px; border-bottom: 1px dashed rgba(129,190,185,.15); font-size: 11px; }

.plan-grid, .card-grid, .boss-grid, .map-grid { display: grid; gap: 7px; }
.plan-grid, .map-grid { grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); }
.card-grid { grid-template-columns: repeat(auto-fill, minmax(168px, 1fr)); }
.boss-grid { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.plan-card, .mini-card { border: 1px solid var(--line); background: rgba(6,18,19,.5); border-radius: 12px; padding: 11px; text-align: left; }
.plan-card.active, .mini-card.active { border-color: var(--cyan); box-shadow: inset 0 0 0 1px rgba(114,226,213,.15); background: rgba(20,58,57,.55); }
.plan-card strong, .mini-card strong { display: block; font-size: 12px; margin-bottom: 5px; }
.plan-card span, .mini-card span { color: var(--muted); font-size: 9px; line-height: 1.4; }

.array-grid { display: grid; grid-template-columns: repeat(6, minmax(74px, 1fr)); gap: 7px; }
.array-slot { min-width: 0; padding: 0; border-radius: 12px; border: 1px solid var(--line); background: #0a1d1e; overflow: hidden; text-align: left; }
.array-slot.selected { border-color: var(--amber); box-shadow: 0 0 0 1px rgba(217,168,93,.25); }
.array-slot img { width: 100%; height: clamp(72px, 9vw, 116px); object-fit: cover; display: block; filter: saturate(.85); }
.array-slot div { padding: 6px 7px; }
.array-slot b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 10px; }
.array-slot small { color: var(--cyan); font-size: 8px; }

.filter-row { display: flex; gap: 7px; overflow-x: auto; padding-bottom: 3px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.chip { flex: 0 0 auto; min-height: 34px; padding: 7px 11px; border-radius: 999px; border: 1px solid var(--line); background: #0b2021; color: var(--muted); font-size: 10px; }
.chip.active { color: #06201e; background: var(--cyan); border-color: var(--cyan); font-weight: 800; }

.catalog-card { border: 1px solid var(--line); background: #0a1c1d; border-radius: 11px; overflow: hidden; min-width: 0; }
.catalog-card.locked { filter: grayscale(.78); opacity: .6; }
.catalog-card img { width: 100%; height: 106px; object-fit: cover; display: block; background: #0b191b; }
.catalog-card .body { padding: 8px; }
.catalog-card h3 { margin: 0 0 3px; font-size: 11px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.catalog-card p { margin: 0 0 7px; color: var(--muted); line-height: 1.35; font-size: 8px; min-height: 22px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.catalog-card footer { display: flex; align-items: center; justify-content: space-between; gap: 6px; font-size: 9px; }

.rule-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(310px, 1fr)); gap: 7px; max-height: 430px; overflow: auto; padding-right: 2px; }
.rule-card { display: grid; grid-template-columns: 50px 1fr auto; gap: 7px; align-items: center; border: 1px solid var(--line); background: rgba(7,20,21,.72); border-radius: 10px; overflow: hidden; padding-right: 7px; }
.rule-card.selected { border-color: var(--cyan); }
.rule-card img { width: 50px; height: 58px; object-fit: cover; }
.rule-card h4 { margin: 0 0 3px; font-size: 10px; }
.rule-card p { margin: 0; color: var(--muted); font-size: 7px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.world-hero, .boss-hero { height: min(38dvh, 340px); min-height: 210px; position: relative; background-size: cover; background-position: center 42%; display: flex; align-items: end; }
.world-hero::after, .boss-hero::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, transparent 20%, rgba(5,14,15,.38) 55%, #091819); }
.world-hero > div, .boss-hero > div { z-index: 1; position: relative; padding: 18px; }
.world-hero h2, .boss-hero h2 { margin: 0 0 5px; }
.world-hero p, .boss-hero p { margin: 0; color: #b9c8c5; font-size: 10px; line-height: 1.5; }
.node-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(290px, 1fr)); gap: 7px; }
.node-card { border: 1px solid var(--line); background: rgba(7,20,21,.7); padding: 9px; border-radius: 10px; }
.node-top { display: flex; justify-content: space-between; gap: 10px; align-items: start; }
.node-card h4 { margin: 0 0 4px; font-size: 12px; }
.node-card p { margin: 0; color: var(--muted); font-size: 9px; }
.progress { height: 5px; background: #061011; border-radius: 999px; overflow: hidden; margin-top: 10px; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, #2a7772, var(--cyan)); }

.boss-card { padding: 0; overflow: hidden; border: 1px solid var(--line); background: #0a1c1d; border-radius: 10px; text-align: left; }
.boss-card img { width: 100%; height: 96px; object-fit: cover; display: block; }
.boss-card div { padding: 7px; }
.boss-card b { font-size: 9px; display: -webkit-box; min-height: 24px; line-height: 1.3; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.boss-card small { color: var(--muted); font-size: 8px; }

.side-nav { z-index: 30; min-height: 0; display: grid; grid-template-rows: repeat(5, minmax(58px, 1fr)); padding: 8px 7px max(8px, env(safe-area-inset-bottom)); background: rgba(5,15,16,.96); border-right: 1px solid var(--line); backdrop-filter: blur(18px); }
.side-nav button { min-width: 0; border: 0; border-radius: 12px; background: transparent; color: #78908d; font-size: 10px; display: grid; place-content: center; place-items: center; gap: 5px; }
.side-nav button span { font-size: 21px; line-height: 1; }
.side-nav button.active { color: var(--cyan); background: rgba(30,72,70,.38); box-shadow: inset 2px 0 var(--cyan); }

.modal-backdrop { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: clamp(12px, 3vw, 32px); background: rgba(0,0,0,.7); backdrop-filter: blur(5px); }
.modal { width: min(620px, 100%); max-height: min(88dvh, 680px); overflow: auto; margin: 0; border: 1px solid var(--line-hot); border-radius: 20px; background: #0a1c1d; padding: 18px 16px; box-shadow: 0 24px 80px rgba(0,0,0,.62); }
.modal h2 { margin: 0 0 8px; }
.modal p { color: var(--muted); font-size: 11px; line-height: 1.6; }
.modal .big-reward { font-size: 32px; color: var(--cyan); font-weight: 900; margin: 14px 0; }
.modal textarea { width: 100%; min-height: 120px; resize: vertical; background: #061112; border: 1px solid var(--line); border-radius: 10px; color: var(--text); padding: 10px; font: 10px/1.4 ui-monospace, monospace; }

#toast-root { position: fixed; z-index: 100; left: calc(50% + 41px); bottom: 22px; transform: translateX(-50%); display: grid; gap: 7px; width: min(70%, 420px); pointer-events: none; }
.toast { background: rgba(15,42,42,.98); border: 1px solid var(--line-hot); color: var(--text); padding: 11px 13px; border-radius: 11px; text-align: center; font-size: 11px; box-shadow: 0 12px 40px rgba(0,0,0,.4); animation: toast-in .18s ease; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (min-width: 1100px) {
  .main-view { padding: 20px 24px 32px; }
  .card-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .boss-grid { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .plan-grid, .map-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .metric-grid { grid-template-columns: repeat(4, 1fr); }
}

@media (max-width: 900px) and (orientation: landscape) {
  .topbar { height: 54px; grid-template-columns: 150px minmax(320px, 1fr) auto; gap: 7px; padding: 5px 8px; }
  .topbar h1 { font-size: 15px; }
  .eyebrow { font-size: 6px; }
  .icon-button { width: 34px; height: 34px; }
  .header-actions { gap: 4px; }
  .language-switch { height: 34px; grid-template-columns: repeat(2, 30px); padding: 2px; }
  .language-switch button { font-size: 9px; }
  .resource-strip { height: 40px; }
  .resource-strip div { padding: 4px 7px; }
  .resource-strip span { font-size: 7px; }
  .resource-strip strong { font-size: 10px; }
  .workspace { height: calc(100dvh - 54px); grid-template-columns: 62px minmax(0, 1fr); }
  .side-nav { padding: 4px; grid-template-rows: repeat(5, minmax(46px, 1fr)); }
  .side-nav button { font-size: 8px; gap: 2px; }
  .side-nav button span { font-size: 16px; }
  .main-view { padding: 9px 10px 18px; }
  .view-stack { gap: 9px; }
  .view-stack.two-column { grid-template-columns: minmax(350px, 1.1fr) minmax(300px, .9fr); }
  .hero { min-height: calc(100dvh - 72px); }
  .hero-content { padding: 50px 13px 13px; }
  .hero-content h2 { font-size: 20px; }
  .production-number { font-size: 36px; margin: 10px 0; }
  .primary-button, .secondary-button { min-height: 38px; padding: 8px 11px; font-size: 11px; }
  .panel-pad { padding: 9px; }
  .section-heading { margin-bottom: 8px; }
  .section-heading h2, .section-heading h3 { font-size: 13px; }
  .array-grid { grid-template-columns: repeat(6, minmax(68px, 1fr)); }
  .array-slot img { height: 68px; }
  .card-grid, .boss-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .plan-grid, .map-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .catalog-card img { height: 72px; }
  .catalog-card .body { padding: 6px; }
  .catalog-card p { margin-bottom: 5px; min-height: 20px; }
  .boss-card img { height: 70px; }
  .boss-card div { padding: 5px 6px; }
  .rule-list { grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: 340px; }
  .rule-card { grid-template-columns: 42px 1fr auto; gap: 5px; }
  .rule-card img { width: 42px; height: 48px; }
  .world-hero, .boss-hero { height: 180px; min-height: 180px; }
  .modal-backdrop { padding: 10px; }
  .modal { max-height: calc(100dvh - 20px); border-radius: 16px; padding: 14px 15px; }
  #toast-root { left: calc(50% + 31px); bottom: 10px; }
}

.rotate-gate { display: none; }
@media (max-width: 900px) and (orientation: portrait) {
  .app-shell, .boot-screen, #modal-root, #toast-root { display: none !important; }
  .rotate-gate { position: fixed; inset: 0; z-index: 200; display: grid; place-content: center; text-align: center; padding: 30px; background: radial-gradient(circle at 50% 35%, rgba(54,145,139,.18), transparent 35%), #071113; }
  .rotate-gate h2 { margin: 8px 0; color: var(--cyan-soft); }
  .rotate-gate p { margin: 0; color: var(--muted); font-size: 12px; }
  .rotate-icon { margin: 0 auto 12px; width: 72px; height: 48px; display: grid; place-items: center; border: 2px solid var(--line-hot); border-radius: 10px; color: var(--cyan); font-size: 30px; animation: rotate-hint 1.8s ease-in-out infinite; }
  @keyframes rotate-hint { 0%, 100% { transform: rotate(0); } 50% { transform: rotate(90deg); } }
}

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