:root {
  color-scheme: dark;
  --ink: #fff8df;
  --muted: #b8cbc5;
  --deep: #06191b;
  --stage: #0d3030;
  --wine: #4b2438;
  --panel: #102a2b;
  --panel-2: #1b3230;
  --edge: rgba(244, 222, 164, .3);
  --gold: #f0c45b;
  --jade: #58c9a9;
  --coral: #ec786e;
  --sky: #6fb8e5;
  --ivory: #f4e9c7;
  --thread: #f0c45b;
  --thread-rgb: 240, 196, 91;
  --safe-top: max(6px, env(safe-area-inset-top));
  --safe-right: max(8px, env(safe-area-inset-right));
  --safe-bottom: max(6px, env(safe-area-inset-bottom));
  --safe-left: max(8px, env(safe-area-inset-left));
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

* { box-sizing: border-box; letter-spacing: 0; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; }
body { color: var(--ink); background: var(--deep); overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; cursor: pointer; touch-action: manipulation; -webkit-tap-highlight-color: transparent; }
button:focus-visible { outline: 3px solid #fff1a7; outline-offset: 2px; }
button:disabled { cursor: default; }
.hidden { display: none !important; }

.app {
  position: relative;
  width: 100%;
  height: 100%;
  min-height: 100dvh;
  overflow: hidden;
  isolation: isolate;
  background:
    linear-gradient(145deg, rgba(5, 26, 28, .96), rgba(73, 31, 54, .78)),
    url("/games/rune-weave/v9/assets/bg-weave.png") center / 256px repeat;
}
.app::before {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -2;
  opacity: .16;
  pointer-events: none;
  background: url("/games/rune-weave/v9/assets/bg-lattice.png") center / 384px repeat;
}
.app[data-theme="jade"] { --thread: #58c9a9; --thread-rgb: 88, 201, 169; }
.app[data-theme="coral"] { --thread: #ec786e; --thread-rgb: 236, 120, 110; }
.app[data-theme="sky"] { --thread: #6fb8e5; --thread-rgb: 111, 184, 229; }
.app[data-theme="ivory"] { --thread: #f4e9c7; --thread-rgb: 244, 233, 199; }
.app[data-theme="orchid"] { --thread: #c6a0df; --thread-rgb: 198, 160, 223; }

.weave-canvas {
  position: absolute;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
.view { position: relative; width: 100%; height: 100%; overflow: hidden; }

.reward-art, .rail-art, .mini-art {
  display: block;
  background-image: url("/games/rune-weave/v9/assets/reward-objects.webp");
  background-repeat: no-repeat;
  background-size: 300% 200%;
}
.art-life { background-position: 0 0; }
.art-spool { background-position: 50% 0; }
.art-lens { background-position: 100% 0; }
.art-compass { background-position: 0 100%; }
.art-thread { background-position: 50% 100%; }
.art-mantle { background-position: 100% 100%; }
.mini-art { width: 26px; height: 26px; flex: 0 0 26px; }
.rail-art { width: 36px; height: 36px; margin: 0 auto; }

/* Home */
.home-view {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto 50px minmax(0, 1fr) 112px;
  padding-top: var(--safe-top);
  padding-right: var(--safe-right);
  padding-bottom: var(--safe-bottom);
  padding-left: var(--safe-left);
}
.home-head {
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 5px 6px;
}
.brand-lockup { min-width: 0; display: flex; align-items: center; gap: 9px; }
.brand-seal {
  width: 38px;
  height: 38px;
  flex: 0 0 38px;
  border: 2px solid var(--thread);
  border-radius: 50%;
  background-color: rgba(4, 19, 21, .8);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, .04), 0 0 16px rgba(var(--thread-rgb), .28);
  filter: drop-shadow(0 3px 5px rgba(0, 0, 0, .4));
}
.brand-lockup h1 {
  margin: 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(22px, 6vw, 30px);
  line-height: 1;
  white-space: nowrap;
}
.brand-lockup p { margin: 3px 0 0; color: var(--muted); font-size: 10px; font-weight: 800; text-transform: uppercase; white-space: nowrap; }
.wallet { display: flex; align-items: center; gap: 5px; }
.wallet-chip {
  min-width: 58px;
  height: 38px;
  padding: 3px 7px 3px 3px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 3px;
  border: 1px solid var(--edge);
  border-radius: 6px;
  background: rgba(4, 20, 22, .76);
}
.wallet-chip b { color: var(--thread); font-size: 15px; font-variant-numeric: tabular-nums; }
.mode-tabs {
  width: min(440px, 100%);
  min-height: 50px;
  margin: 0 auto;
  padding: 3px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  border: 1px solid var(--edge);
  border-radius: 7px;
  background: rgba(4, 20, 22, .82);
}
.mode-tab {
  min-width: 0;
  min-height: 44px;
  padding: 4px 8px;
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
  white-space: nowrap;
}
.mode-tab.selected { color: #102322; background: var(--thread); }
.mode-tab[data-locked="true"] { opacity: .46; }

.home-main { position: relative; width: min(720px, 100%); min-height: 0; margin: 0 auto; }
.next-goal {
  position: absolute;
  z-index: 3;
  top: 10px;
  left: 50%;
  width: min(520px, calc(100% - 8px));
  min-height: 58px;
  padding: 8px 10px 7px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 90px;
  align-items: center;
  gap: 10px;
  border-left: 3px solid var(--thread);
  border-top: 1px solid var(--edge);
  border-bottom: 1px solid var(--edge);
  background: rgba(4, 22, 24, .8);
  transform: translateX(-50%);
}
.goal-copy { min-width: 0; }
.goal-copy span { display: block; color: var(--thread); font-size: 9px; font-weight: 900; text-transform: uppercase; white-space: nowrap; }
.goal-copy strong { display: block; margin-top: 2px; overflow: hidden; font-size: 15px; line-height: 1.15; text-overflow: ellipsis; white-space: nowrap; }
.goal-copy small { display: block; margin-top: 3px; overflow: hidden; color: var(--muted); font-size: 10px; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.chapter-meter { position: relative; height: 28px; overflow: hidden; border: 1px solid var(--edge); border-radius: 5px; background: rgba(255, 255, 255, .05); }
.chapter-meter span { position: absolute; inset: 0 auto 0 0; width: 0; background: rgba(var(--thread-rgb), .38); transition: width 240ms ease; }
.chapter-meter b { position: relative; z-index: 1; height: 100%; display: grid; place-items: center; font-size: 10px; font-variant-numeric: tabular-nums; }
.home-altar {
  position: absolute;
  z-index: 1;
  left: 50%;
  top: 49%;
  width: min(440px, 86vw, 44vh);
  aspect-ratio: 1.28;
  border-radius: 8px;
  background: url("/games/rune-weave/v9/assets/board-altar.webp") center / cover no-repeat;
  box-shadow: 0 20px 44px rgba(0, 0, 0, .38), inset 0 0 0 1px rgba(255, 255, 255, .14);
  transform: translate(-50%, -50%);
}
.home-altar::before {
  content: "";
  position: absolute;
  inset: 10% 12%;
  border: 1px solid rgba(var(--thread-rgb), .5);
  border-radius: 50%;
  box-shadow: inset 0 0 28px rgba(var(--thread-rgb), .15), 0 0 28px rgba(var(--thread-rgb), .12);
}
.altar-thread { position: absolute; left: 12%; right: 12%; top: 52%; height: 2px; background: var(--thread); box-shadow: 0 0 12px var(--thread); transform: rotate(-8deg); }
.altar-spool { position: absolute; left: 50%; top: 48%; width: 38%; aspect-ratio: 1; transform: translate(-50%, -50%); filter: drop-shadow(0 10px 15px rgba(0,0,0,.45)); }
.loom-level { position: absolute; right: 12%; bottom: 12%; min-width: 34px; height: 34px; display: grid; place-items: center; border: 1px solid var(--thread); border-radius: 50%; background: #132b2b; color: var(--thread); font-family: Georgia, serif; font-weight: 900; }
.start-zone {
  position: absolute;
  z-index: 4;
  top: 78%;
  left: 50%;
  width: min(430px, calc(100% - 4px));
  display: block;
  transform: translateX(-50%);
}
.start-main {
  min-width: 0;
  width: 100%;
  height: 58px;
  padding: 6px 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, .5);
  border-radius: 7px;
  background: var(--thread);
  color: #102322;
  box-shadow: 0 13px 28px rgba(0, 0, 0, .34);
  text-align: left;
}
.start-main strong, .start-main small { display: block; white-space: nowrap; }
.start-main strong { font-size: 18px; line-height: 1; }
.start-main small { margin-top: 5px; font-size: 10px; font-weight: 800; opacity: .7; }
.play-mark { position: relative; width: 28px; height: 28px; flex: 0 0 28px; border: 2px solid currentColor; border-radius: 50%; }
.play-mark::after { content: ""; position: absolute; left: 9px; top: 7px; border-top: 6px solid transparent; border-bottom: 6px solid transparent; border-left: 9px solid currentColor; }
.preboost-btn {
  position: absolute;
  right: 0;
  bottom: calc(100% + 7px);
  min-width: 0;
  width: 132px;
  height: 46px;
  padding: 3px 7px 3px 3px;
  display: grid;
  grid-template-columns: 38px minmax(0, 1fr);
  align-items: center;
  gap: 4px;
  border: 1px solid rgba(111, 184, 229, .7);
  border-radius: 7px;
  background: #153746;
  color: #dff4ff;
  text-align: left;
}
.preboost-art { width: 38px; height: 38px; }
.preboost-copy { min-width: 0; display: grid; grid-template-columns: auto 1fr; align-items: baseline; column-gap: 3px; }
.preboost-copy b { grid-column: 1 / -1; color: var(--sky); font-size: 8px; line-height: 1; white-space: nowrap; }
.preboost-copy strong { color: var(--ivory); font-size: 16px; line-height: 1; white-space: nowrap; }
.preboost-copy small { overflow: hidden; color: var(--muted); font-size: 8px; font-weight: 900; line-height: 1; text-overflow: ellipsis; white-space: nowrap; }
.preboost-btn.locked { opacity: .38; }
.video-mark { width: 22px; height: 17px; display: inline-grid; place-items: center; flex: 0 0 22px; border: 1px solid currentColor; border-radius: 3px; }
.video-mark i { width: 0; height: 0; margin-left: 2px; border-top: 4px solid transparent; border-bottom: 4px solid transparent; border-left: 6px solid currentColor; }
.system-rail {
  min-width: 0;
  display: grid;
  grid-template-columns: repeat(var(--rail-count, 5), minmax(0, 72px));
  justify-content: center;
  align-items: start;
  gap: 3px;
  border-top: 1px solid var(--edge);
  padding: 4px 0 0;
}
.system-rail button {
  position: relative;
  min-width: 0;
  height: 56px;
  min-height: 56px;
  padding: 1px 1px 2px;
  border-radius: 5px;
  background: rgba(4, 20, 22, .66);
  color: var(--muted);
}
.system-rail button:hover { background: rgba(31, 61, 59, .9); color: var(--ink); }
.system-rail button[data-locked="true"] { opacity: .4; }
.system-rail button[data-preview="true"]::after { content: ""; position: absolute; top: 4px; right: 4px; width: 6px; height: 6px; border-radius: 50%; background: var(--coral); }
.system-rail span { display: block; overflow: hidden; font-size: 9px; font-weight: 800; line-height: 1.1; text-overflow: ellipsis; white-space: nowrap; }
.system-rail .art-lens { transform: translateX(1px); }
.system-rail .art-thread { transform: translate(-1px, 1px); }
.system-rail .art-compass { transform: translateY(1px); }

/* Play */
.play-view { display: grid; grid-template-rows: 50px minmax(0, 1fr); padding: var(--safe-top) var(--safe-right) var(--safe-bottom) var(--safe-left); }
.play-head {
  min-width: 0;
  display: grid;
  grid-template-columns: 46px minmax(54px, 1fr) auto 46px;
  align-items: center;
  gap: 5px;
  border-bottom: 1px solid var(--edge);
}
.icon-btn { position: relative; width: 44px; height: 44px; padding: 0; border: 1px solid var(--edge); border-radius: 6px; background: rgba(5, 24, 26, .9); }
.home-icon::before { content: ""; position: absolute; left: 12px; top: 17px; width: 18px; height: 15px; border: 2px solid var(--thread); border-top: 0; }
.home-icon::after { content: ""; position: absolute; left: 12px; top: 10px; width: 15px; height: 15px; border-left: 2px solid var(--thread); border-top: 2px solid var(--thread); transform: rotate(45deg); }
.pause-icon::before, .pause-icon::after { content: ""; position: absolute; top: 12px; width: 5px; height: 20px; border-radius: 1px; background: var(--thread); }
.pause-icon::before { left: 14px; }
.pause-icon::after { right: 14px; }
.close-icon::before, .close-icon::after { content: ""; position: absolute; left: 11px; top: 20px; width: 20px; height: 2px; background: var(--thread); transform: rotate(45deg); }
.close-icon::after { transform: rotate(-45deg); }
.play-id { min-width: 0; }
.play-id span { display: block; overflow: hidden; color: var(--muted); font-size: 9px; font-weight: 800; text-overflow: ellipsis; text-transform: uppercase; white-space: nowrap; }
.play-id strong { display: block; font-size: 21px; line-height: 1; }
.play-counters { display: flex; align-items: center; gap: 4px; }
.counter { min-width: 53px; height: 38px; padding: 2px 6px 2px 2px; display: flex; align-items: center; justify-content: center; gap: 1px; border: 1px solid var(--edge); border-radius: 5px; background: rgba(5, 24, 26, .74); }
.counter b { color: var(--thread); font-size: 15px; font-variant-numeric: tabular-nums; }
.moves-counter { min-width: 60px; padding: 3px 7px; display: grid; grid-template-columns: auto auto; gap: 4px; }
.moves-counter small { color: var(--muted); font-size: 8px; font-weight: 800; text-transform: uppercase; }
.moves-counter b { font-size: 18px; }
.moves-counter.urgent { border-color: var(--coral); background: rgba(100, 35, 42, .75); }
.play-layout { min-height: 0; display: grid; grid-template-rows: auto minmax(0, 1fr) 50px; gap: 5px; }
.mission-panel { min-width: 0; min-height: 0; padding: 5px 2px 2px; display: grid; grid-template-columns: 64px minmax(0, 1fr); grid-template-areas: "title queue" "tasks tasks" "copy copy"; gap: 3px 6px; align-items: center; }
.order-title { grid-area: title; }
.order-title span, .order-title b { display: block; white-space: nowrap; }
.order-title span { color: var(--muted); font-size: 9px; font-weight: 900; text-transform: uppercase; }
.order-title b { margin-top: 3px; color: var(--thread); font-size: 12px; }
.order-queue { grid-area: queue; min-width: 0; height: 38px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 4px; }
.order-card { min-width: 0; height: 38px; padding: 2px; display: flex; align-items: center; justify-content: center; gap: 4px; border: 1px solid var(--edge); border-radius: 5px; background: rgba(5, 24, 26, .78); color: var(--muted); }
.order-card.current { border-color: var(--thread); color: var(--ink); box-shadow: inset 0 0 0 1px rgba(var(--thread-rgb), .18); }
.order-swatch { position: relative; width: 21px; height: 21px; flex: 0 0 21px; border: 1px solid rgba(255,255,255,.42); border-radius: 5px; background: var(--rune); box-shadow: inset 0 -4px rgba(0,0,0,.2); }
.order-swatch::after { content: ""; position: absolute; inset: 6px; border: 2px solid rgba(4, 24, 25, .75); transform: rotate(45deg); }
.order-card b { font-size: 10px; white-space: nowrap; }
.task-strip { grid-area: tasks; min-width: 0; min-height: 19px; display: flex; align-items: center; gap: 4px; overflow: hidden; }
.task-chip { min-width: 0; height: 19px; padding: 1px 6px; display: flex; align-items: center; gap: 4px; border: 1px solid rgba(111,184,229,.5); border-radius: 4px; background: rgba(18, 52, 64, .7); color: #dcefff; font-size: 9px; font-weight: 800; white-space: nowrap; }
.task-chip.done { border-color: var(--jade); background: rgba(26, 76, 63, .8); color: #e7fff5; }
.task-chip i { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.live-instruction { grid-area: copy; margin: 0; overflow: hidden; color: var(--muted); font-size: 10px; font-weight: 700; line-height: 1.2; text-overflow: ellipsis; white-space: nowrap; }
.board-column { min-width: 0; min-height: 0; display: grid; place-items: center; }
.board-frame {
  position: relative;
  width: min(100%, 590px);
  max-height: 100%;
  padding: 8px;
  border: 1px solid rgba(244, 222, 164, .32);
  border-radius: 8px;
  background: url("/games/rune-weave/v9/assets/board-altar.webp") center / cover no-repeat, #142d2c;
  box-shadow: 0 18px 42px rgba(0,0,0,.4), inset 0 1px rgba(255,255,255,.08);
}
.board {
  --cols: 7;
  --rows: 8;
  position: relative;
  z-index: 2;
  width: min(100%, calc(var(--board-h, 520px) * var(--cols) / var(--rows)));
  max-height: var(--board-h, 520px);
  aspect-ratio: var(--cols) / var(--rows);
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  grid-template-rows: repeat(var(--rows), minmax(0, 1fr));
  gap: clamp(3px, .8vw, 7px);
  touch-action: manipulation;
}
.zone-shade { position: absolute; z-index: 1; pointer-events: none; opacity: 0; border: 2px solid var(--sky); background: rgba(111,184,229,.1); transition: opacity 150ms ease; }
.zone-shade.left { left: 8px; top: 8px; bottom: 8px; width: calc(50% - 8px); opacity: 1; border-right: 0; }
.zone-shade.right { right: 8px; top: 8px; bottom: 8px; width: calc(50% - 8px); opacity: 1; border-left: 0; }
.zone-shade.center { left: 30%; right: 30%; top: 28%; bottom: 28%; opacity: 1; }
.cell { position: relative; min-width: 0; min-height: 0; border-radius: 5px; background: rgba(0,0,0,.22); box-shadow: inset 0 0 0 1px rgba(255,255,255,.04); }
.tile { position: absolute; inset: 0; z-index: 2; width: 100%; height: 100%; min-width: 0; min-height: 0; padding: 0; overflow: hidden; border: 1px solid rgba(255,255,255,.38); border-radius: 6px; background: linear-gradient(145deg, rgba(255,255,255,.35), transparent 38%), var(--rune); box-shadow: inset 0 -5px rgba(0,0,0,.2), inset 0 2px rgba(255,255,255,.2), 0 3px 0 rgba(0,0,0,.3); transform: translateY(-1px); transition: opacity 140ms ease, transform 130ms ease, filter 130ms ease; }
.tile:active { transform: translateY(1px) scale(.96); }
.tile.clearing { opacity: 0; transform: scale(1.15) rotate(4deg); filter: brightness(1.65); }
.tile.reject { animation: reject 180ms linear 1; }
.tile.hint { animation: hintPulse 850ms ease-in-out 2; }
.tile.first-action { animation: firstPulse 1.2s ease-in-out infinite; }
.tile.spool::before { content: ""; position: absolute; inset: 7%; z-index: 2; background: url("/games/rune-weave/v9/assets/reward-objects.webp") 50% 0 / 300% 200% no-repeat; filter: drop-shadow(0 0 5px #fff0a3); }
.tile.spool::after { content: "+1"; position: absolute; z-index: 3; right: 2px; bottom: 1px; color: #fff8cf; font-size: clamp(7px, 2vw, 11px); font-weight: 900; text-shadow: 0 1px 3px #000; }
.rune-mark { position: absolute; left: 50%; top: 50%; width: 38%; height: 38%; border: max(2px, .07em) solid rgba(4, 24, 25, .74); border-radius: 3px; transform: translate(-50%, -50%) rotate(45deg); }
.tile[data-color="1"] .rune-mark { border-radius: 50%; transform: translate(-50%, -50%); }
.tile[data-color="2"] .rune-mark { width: 0; height: 0; border: 0; border-left: .36em solid transparent; border-right: .36em solid transparent; border-bottom: .64em solid rgba(4,24,25,.74); transform: translate(-50%, -53%); }
.tile[data-color="3"] .rune-mark { border-radius: 50%; box-shadow: inset 0 0 0 .12em rgba(255,255,255,.2); transform: translate(-50%, -50%); }
.tile[data-color="4"] .rune-mark { clip-path: polygon(25% 0,75% 0,100% 50%,75% 100%,25% 100%,0 50%); transform: translate(-50%, -50%); }
.tile[data-color="5"] .rune-mark { border-radius: 1px; transform: translate(-50%, -50%); }
.coach { display: none; }
.tool-row { min-width: 0; padding-right: 52px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 5px; }
.tool-btn { min-width: 0; min-height: 44px; padding: 2px 6px; display: grid; grid-template-columns: 28px minmax(0, 1fr) auto; align-items: center; gap: 4px; border: 1px solid var(--edge); border-radius: 6px; background: rgba(5, 24, 26, .88); }
.tool-btn .rail-art { width: 28px; height: 28px; margin: 0; }
.tool-btn b { overflow: hidden; font-size: 10px; text-align: left; text-overflow: ellipsis; white-space: nowrap; }
.tool-btn small { min-width: 19px; color: var(--thread); font-size: 10px; font-weight: 900; white-space: nowrap; }
.tool-btn[data-locked="true"] { opacity: .42; }
.undo-icon { position: relative; width: 26px; height: 26px; border: 2px solid var(--thread); border-right-color: transparent; border-radius: 50%; }
.undo-icon::before { content: ""; position: absolute; left: -4px; top: -3px; border-top: 5px solid transparent; border-bottom: 5px solid transparent; border-right: 8px solid var(--thread); transform: rotate(28deg); }
.ad-tool { border-color: rgba(111,184,229,.55); }

/* Overlays and fixed-height panels */
.overlay { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left)); background: rgba(2, 12, 14, .8); backdrop-filter: blur(8px); }
.panel { width: min(430px, 100%); max-height: calc(100dvh - 16px); overflow: hidden; padding: clamp(14px, 4vw, 24px); border: 1px solid rgba(255,255,255,.34); border-radius: 8px; background: linear-gradient(150deg, #243a34, #241d30); box-shadow: 0 24px 70px rgba(0,0,0,.58); text-align: center; }
.overlay .panel.dfl-panel { align-items: stretch; gap: 0; width: min(430px, 100%); max-width: 100%; overflow: hidden; padding: clamp(14px, 4vw, 24px); border-radius: 8px; }
.panel-rule { display: block; width: 68px; height: 4px; margin: 0 auto 12px; border-radius: 2px; background: var(--thread); box-shadow: 0 0 14px rgba(var(--thread-rgb),.45); }
.panel-kicker, .panel-head span { display: block; color: var(--thread); font-size: 9px; font-weight: 900; text-transform: uppercase; white-space: nowrap; }
.panel h2 { margin: 4px 0 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(27px, 8vw, 38px); line-height: 1; }
.panel p { margin: 8px auto 12px; max-width: 35ch; color: var(--muted); font-size: 12px; line-height: 1.35; }
.compact-panel { width: min(360px, 100%); }
.reward-panel { width: min(390px, 100%); }
.reward-hero { width: 112px; height: 112px; margin: -6px auto 2px; filter: drop-shadow(0 10px 13px rgba(0,0,0,.4)); }
.reward-hero.dimmed { filter: grayscale(.4) brightness(.76) drop-shadow(0 8px 12px rgba(0,0,0,.4)); }
.panel-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 8px; }
.action, .ad-action { min-width: 0; min-height: 46px; padding: 7px 10px; border: 1px solid var(--edge); border-radius: 6px; background: rgba(255,255,255,.07); font-size: 12px; font-weight: 900; white-space: nowrap; }
.action.primary { border-color: rgba(255,255,255,.45); background: var(--thread); color: #102322; }
.action.wide { width: 100%; margin-top: 7px; }
.ad-action { width: 100%; display: flex; align-items: center; justify-content: center; gap: 8px; border-color: rgba(111,184,229,.72); background: #153746; color: #e4f5ff; white-space: normal; }
.action:disabled, .ad-action:disabled { opacity: .42; }
.text-action { min-height: 44px; margin-top: 4px; padding: 4px 10px; background: transparent; color: #ffb4ab; font-size: 11px; font-weight: 800; }
.star-line { height: 18px; margin: 5px 0 8px; display: flex; justify-content: center; gap: 5px; }
.star-line i { width: 34px; height: 7px; border: 1px solid var(--edge); border-radius: 2px; background: rgba(255,255,255,.06); }
.star-line i.on { border-color: var(--thread); background: var(--thread); box-shadow: 0 0 9px rgba(var(--thread-rgb), .4); }
.status-line { min-height: 16px; margin: 7px 0 0 !important; font-size: 10px !important; }
.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 8px 0; }
.summary-grid span { padding: 7px; border-top: 1px solid var(--edge); border-bottom: 1px solid var(--edge); }
.summary-grid small, .summary-grid b { display: block; }
.summary-grid small { color: var(--muted); font-size: 9px; }
.summary-grid b { margin-top: 2px; color: var(--thread); font-size: 19px; }
.panel-head { height: 46px; display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; }
.panel-head h2 { margin-top: 2px; font-family: inherit; font-size: 22px; }
.system-panel { width: min(560px, 100%); height: min(520px, calc(100dvh - 16px)); padding: 10px 12px 12px; display: grid; grid-template-rows: 46px minmax(0, 1fr); }
.overlay .system-panel.dfl-panel { width: min(560px, 100%); height: min(520px, calc(100dvh - 16px)); padding: 10px 12px 12px; display: grid; grid-template-rows: 46px minmax(0, 1fr); }
.system-body { min-width: 0; min-height: 0; overflow: hidden; text-align: left; }
.level-map { height: 100%; display: grid; grid-template-rows: auto 1fr auto; gap: 8px; }
.map-summary { min-width: 0; display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 11px; font-weight: 800; }
.map-summary strong { color: var(--thread); font-size: 14px; white-space: nowrap; }
.level-grid { min-height: 0; display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); grid-template-rows: repeat(2, minmax(52px, 1fr)); gap: 6px; }
.level-cell { position: relative; min-width: 0; min-height: 52px; border: 1px solid var(--edge); border-radius: 6px; background: rgba(5,24,26,.76); text-align: center; }
.level-cell.selected { border-color: var(--thread); background: rgba(var(--thread-rgb),.14); }
.level-cell[data-locked="true"] { opacity: .38; }
.level-cell b { display: block; font-size: 17px; }
.level-cell small { display: block; margin-top: 3px; color: var(--thread); font-size: 8px; white-space: nowrap; }
.map-actions { display: grid; grid-template-columns: 44px 1fr 44px; gap: 6px; }
.map-actions button { min-height: 44px; border: 1px solid var(--edge); border-radius: 6px; background: rgba(255,255,255,.06); font-size: 12px; font-weight: 900; }
.system-list { height: 100%; display: grid; grid-auto-rows: minmax(0, 1fr); gap: 6px; }
.system-row { min-width: 0; min-height: 58px; padding: 6px 8px; display: grid; grid-template-columns: 54px minmax(0,1fr) auto; align-items: center; gap: 8px; border-top: 1px solid var(--edge); border-bottom: 1px solid var(--edge); }
.system-row .reward-art { width: 50px; height: 50px; }
.system-row strong, .system-row small { display: block; min-width: 0; }
.system-row strong { overflow: hidden; font-size: 12px; text-overflow: ellipsis; white-space: nowrap; }
.system-row small { margin-top: 3px; color: var(--muted); font-size: 9px; line-height: 1.2; }
.system-row button { min-width: 72px; min-height: 44px; padding: 4px 7px; border: 1px solid var(--edge); border-radius: 5px; background: rgba(255,255,255,.07); font-size: 10px; font-weight: 900; white-space: nowrap; }
.system-row button.primary { background: var(--thread); color: #102322; }
.skin-strip { height: 100%; display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 7px; align-items: stretch; }
.skin-button { position: relative; min-width: 0; padding: 5px; border: 1px solid var(--edge); border-radius: 7px; background: rgba(5,24,26,.76); }
.skin-button .reward-art { width: min(92px, 100%); aspect-ratio: 1; margin: 0 auto; }
.skin-button strong, .skin-button small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.skin-button strong { font-size: 11px; }
.skin-button small { margin-top: 3px; color: var(--muted); font-size: 9px; }
.skin-button.selected { border-color: var(--thread); }
.skin-button[data-locked="true"] { opacity: .58; }
.toast { position: fixed; z-index: 120; left: 50%; bottom: max(12px, env(safe-area-inset-bottom)); max-width: min(88vw, 450px); min-height: 38px; padding: 9px 13px; display: grid; place-items: center; border: 1px solid var(--edge); border-radius: 6px; background: rgba(3,17,19,.96); color: var(--ink); font-size: 11px; font-weight: 800; text-align: center; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; transition: opacity 150ms ease, transform 150ms ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.burst { position: fixed; z-index: 40; width: 12px; height: 12px; pointer-events: none; background: var(--thread); -webkit-mask: url("/games/rune-weave/v9/assets/fx-snap.png") center / contain no-repeat; mask: url("/games/rune-weave/v9/assets/fx-snap.png") center / contain no-repeat; animation: burst 540ms ease-out forwards; }
.float-score { position: fixed; z-index: 41; pointer-events: none; color: #fff6c9; font-size: 17px; font-weight: 900; text-shadow: 0 2px 4px #000; animation: floatScore 620ms ease-out forwards; }
.grant-art { animation: rewardArrive 680ms cubic-bezier(.2,.8,.2,1) both; }

@keyframes firstPulse { 0%,100%{filter:brightness(1);box-shadow:inset 0 -5px rgba(0,0,0,.2),0 3px 0 rgba(0,0,0,.3)} 50%{filter:brightness(1.22);box-shadow:0 0 0 3px #fff0a6,0 0 20px var(--thread)} }
@keyframes hintPulse { 0%,100%{filter:brightness(1)} 50%{filter:brightness(1.55);box-shadow:0 0 0 3px #fff,0 0 24px var(--sky)} }
@keyframes reject { 0%,100%{transform:translateX(0) translateY(-1px)} 25%{transform:translateX(-4px) translateY(-1px)} 75%{transform:translateX(4px) translateY(-1px)} }
@keyframes burst { from{opacity:1;transform:translate(0,0) rotate(0)} to{opacity:0;transform:translate(var(--dx),var(--dy)) rotate(150deg)} }
@keyframes floatScore { from{opacity:1;transform:translate(-50%,0) scale(.9)} to{opacity:0;transform:translate(-50%,-40px) scale(1.08)} }
@keyframes rewardArrive { 0%{opacity:0;transform:translateY(18px) scale(.82)} 60%{opacity:1;transform:translateY(-4px) scale(1.08)} 100%{opacity:1;transform:none} }

@media (max-width: 430px) {
  .home-head { min-height: 50px; }
  .brand-seal { width: 32px; height: 32px; flex-basis: 32px; }
  .brand-lockup h1 { font-size: 21px; }
  .brand-lockup p { display: none; }
  .wallet-chip { min-width: 50px; height: 34px; padding-right: 5px; }
  .mini-art { width: 23px; height: 23px; flex-basis: 23px; }
  .home-view { grid-template-rows: auto 50px minmax(0,1fr) 112px; }
  .mode-tabs { min-height: 50px; }
  .mode-tab { min-height: 44px; font-size: 11px; }
  .next-goal { top: 6px; min-height: 52px; grid-template-columns: minmax(0,1fr) 76px; padding: 6px 8px; }
  .goal-copy strong { font-size: 13px; }
  .goal-copy small { font-size: 9px; }
  .start-zone { width: 100%; }
  .start-main { padding: 6px 11px; }
  .preboost-btn { width: 122px; grid-template-columns: 36px minmax(0,1fr); }
  .preboost-art { width: 36px; height: 36px; }
  .system-rail { gap: 2px; }
  .system-rail button { min-height: 52px; }
  .rail-art { width: 31px; height: 31px; }
  .system-rail span { font-size: 8px; }
  .map-actions { padding-right: 52px; padding-left: 52px; }
  .play-view { grid-template-rows: 46px minmax(0,1fr); }
  .play-head { grid-template-columns: 44px minmax(38px,1fr) auto 44px; gap: 3px; }
  .icon-btn { width: 44px; height: 44px; }
  .counter { min-width: 47px; height: 35px; }
  .moves-counter { min-width: 52px; padding: 2px 4px; }
  .mission-panel { grid-template-columns: 52px minmax(0,1fr); padding-top: 3px; }
  .order-queue { height: 35px; }
  .order-card { height: 35px; gap: 2px; }
  .order-swatch { width: 18px; height: 18px; flex-basis: 18px; }
  .order-swatch::after { inset: 5px; border-width: 1px; }
  .live-instruction { font-size: 9px; }
  .board-frame { padding: 6px; }
  .zone-shade.left { left: 6px; top: 6px; bottom: 6px; }
  .zone-shade.right { right: 6px; top: 6px; bottom: 6px; }
  .tool-btn { padding: 2px 4px; grid-template-columns: 25px minmax(0,1fr) auto; }
  .tool-btn .rail-art { width: 25px; height: 25px; }
  .tool-btn b, .tool-btn small { font-size: 9px; }
  .tool-row { grid-template-columns: minmax(0,1fr) minmax(0,1fr) 48px; }
  #runSupplyBtn { padding: 2px; grid-template-columns: 1fr; grid-template-rows: 20px 12px; place-items: center; gap: 0; }
  #runSupplyBtn .video-mark { width: 22px; height: 17px; }
  #runSupplyBtn b { display: none; }
  #runSupplyBtn small { min-width: 0; font-size: 7px; }
}

@media (max-height: 520px) and (orientation: portrait) {
  .home-view { grid-template-rows: auto 50px minmax(0,1fr) 112px; }
  .home-head { min-height: 46px; }
  .home-altar { width: min(300px, 74vw, 29vh); top: 49%; }
  .loom-level { right: auto; left: 12%; }
  .next-goal { top: 3px; min-height: 48px; }
  .goal-copy small { display: none; }
  .start-zone { top: 70%; }
  .start-main { height: 54px; }
  .preboost-btn { height: 44px; bottom: calc(100% + 5px); }
  .system-rail button { height: 54px; min-height: 54px; }
  .rail-art { width: 27px; height: 27px; }
  .play-layout { grid-template-columns: minmax(0,1fr) 48px; grid-template-rows: auto minmax(0,1fr); gap: 3px; }
  .mission-panel { grid-column: 1 / -1; grid-row: 1; }
  .board-column { grid-column: 1; grid-row: 2; }
  .board-frame { padding: 2px; }
  .zone-shade.left { left: 2px; top: 2px; bottom: 2px; }
  .zone-shade.right { right: 2px; top: 2px; bottom: 2px; }
  .mission-panel { padding-top: 2px; gap: 2px 4px; }
  .task-strip { min-height: 17px; }
  .task-chip { height: 17px; font-size: 8px; }
  .live-instruction { display: block; font-size: 8px; }
  .tool-row { grid-column: 2; grid-row: 2; grid-template-columns: 1fr; grid-template-rows: repeat(3, 44px); align-content: start; gap: 3px; padding: 0 0 52px; }
  .tool-btn, #runSupplyBtn { min-height: 44px; padding: 1px; grid-template-columns: 1fr; grid-template-rows: 27px 12px; place-items: center; gap: 0; }
  .tool-btn b { display: none; }
  .tool-btn small, #runSupplyBtn small { position: static; min-width: 0; opacity: 1; font-size: 8px; pointer-events: auto; }
  .panel { padding: 9px 12px; }
  .reward-hero { width: 74px; height: 74px; margin-top: -4px; }
  .panel h2 { font-size: 26px; }
  .panel p { margin: 5px auto 7px; font-size: 10px; }
  .ad-action { min-height: 44px; }
  .panel-actions { margin-top: 5px; }
  .star-line { margin: 3px 0 5px; }
  .system-panel { padding: 7px 9px; }
}

@media (max-height: 620px) and (orientation: portrait) {
  .system-panel,
  .overlay .system-panel.dfl-panel {
    align-self: start;
    height: min(520px, calc(100dvh - 100px));
  }
}

@media (orientation: landscape) {
  .home-view { grid-template-rows: 46px minmax(0,1fr); grid-template-columns: minmax(0,1fr) 62px; padding-top: var(--safe-top); }
  .home-head { grid-column: 1; grid-row: 1; min-height: 44px; padding: 1px 6px; }
  .brand-seal { width: 32px; height: 32px; flex-basis: 32px; }
  .brand-lockup h1 { font-size: 20px; }
  .brand-lockup p { display: none; }
  .wallet { margin-right: 3px; }
  .wallet-chip { height: 34px; min-width: 50px; }
  .mode-tabs { position: absolute; z-index: 8; top: calc(var(--safe-top) + 1px); left: 50%; width: min(260px, 36vw); min-height: 50px; transform: translateX(-50%); }
  .mode-tab { min-height: 44px; font-size: 10px; }
  .home-main { grid-column: 1; grid-row: 2; width: 100%; }
  .next-goal { top: 12px; left: 18px; width: min(310px, 44%); min-height: 58px; transform: none; }
  .home-altar { left: 66%; top: 46%; width: min(330px, 42vw, 68vh); }
  .start-zone { top: 67%; left: 18px; width: min(330px, 46%); transform: none; }
  .system-rail { grid-column: 2; grid-row: 1 / 3; grid-template-columns: 1fr; grid-template-rows: repeat(var(--rail-count, 5), minmax(0,1fr)); gap: 2px; padding: 2px 0 52px 4px; border-top: 0; border-left: 1px solid var(--edge); }
  .system-rail button { min-height: 44px; }
  .rail-art { width: 30px; height: 30px; }
  .play-view { grid-template-rows: 44px minmax(0,1fr); }
  .play-head { grid-template-columns: 44px minmax(40px,1fr) auto 44px; }
  .play-layout { grid-template-columns: minmax(174px, 226px) minmax(0,1fr); grid-template-rows: minmax(0,1fr) 50px; gap: 5px 8px; }
  .mission-panel { grid-column: 1; grid-row: 1; padding: 6px 2px; display: flex; flex-direction: column; align-items: stretch; gap: 6px; }
  .order-title { display: flex; align-items: center; justify-content: space-between; }
  .order-title b { margin-top: 0; }
  .order-queue { width: 100%; flex: 0 0 42px; }
  .order-card { height: 42px; display: grid; place-items: center; gap: 1px; }
  .task-strip { flex-wrap: wrap; overflow: visible; }
  .live-instruction { overflow: visible; white-space: normal; }
  .board-column { grid-column: 2; grid-row: 1 / 3; }
  .board-frame { width: auto; height: 100%; max-width: 100%; }
  .board { height: 100%; width: auto; max-width: 100%; gap: 3px; }
  .tool-row { grid-column: 1; grid-row: 2; padding-right: 0; }
  .tool-btn { grid-template-columns: 24px minmax(0,1fr); grid-template-rows: 1fr; }
  .tool-btn small { position: absolute; opacity: 0; pointer-events: none; }
  #runSupplyBtn { grid-template-columns: 1fr; place-items: center; }
  #runSupplyBtn b { display: none; }
  .system-panel { height: min(350px, calc(100dvh - 12px)); width: min(620px, calc(100vw - 16px)); }
  .overlay .system-panel.dfl-panel { height: min(350px, calc(100dvh - 12px)); width: min(620px, calc(100vw - 16px)); }
  .reward-panel { width: min(520px, calc(100vw - 16px)); }
  .overlay .reward-panel.dfl-panel { width: min(520px, calc(100vw - 16px)); }
  .reward-panel .reward-hero { width: 66px; height: 66px; float: left; margin: 0 10px 0 0; }
  .reward-panel p { margin-top: 4px; margin-bottom: 7px; line-height: 1.25; }
  .reward-panel h2, .reward-panel p, .reward-panel .panel-kicker { text-align: left; }
  .reward-panel .panel-actions, .reward-panel .ad-action, .reward-panel .star-line, .reward-panel .summary-grid { clear: both; }
}

/* The platform owns the lower-right audio control. Game actions always leave
   this 52px square free at the 320px floor and in landscape. */
#__juice_mute {
  right: max(6px, env(safe-area-inset-right)) !important;
  bottom: max(6px, env(safe-area-inset-bottom)) !important;
  width: 44px !important;
  height: 44px !important;
  min-width: 44px !important;
  min-height: 44px !important;
}

@media (orientation: landscape) and (max-width: 650px) {
  .brand-lockup h1 { font-size: 16px; }
  .brand-seal { display: none; }
  .wallet-chip:first-child { display: none; }
  .mode-tabs { left: 48%; width: 210px; }
  .next-goal { left: 8px; width: 43%; }
  .start-zone { left: 8px; width: 44%; }
  .preboost-btn { width: 116px; height: 42px; grid-template-columns: 34px minmax(0,1fr); }
  .preboost-art { width: 34px; height: 34px; }
  .start-main strong { font-size: 15px; }
  .home-altar { left: 68%; }
  .play-layout { grid-template-columns: minmax(148px, 184px) minmax(0,1fr); gap: 3px 5px; }
  .mission-panel { gap: 3px; padding-top: 3px; }
  .order-queue { flex-basis: 36px; }
  .order-card { height: 36px; }
  .live-instruction { display: none; }
  .task-chip { font-size: 8px; }
}

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