:root {
  --sbd-ink: #eaffea;
  --sbd-muted: #89aa9a;
  --sbd-panel: rgba(11, 29, 24, .96);
  --sbd-line: rgba(177, 237, 174, .16);
  --sbd-green: #9bea72;
  --sbd-gold: #ffd574;
  --sbd-red: #ff7b76;
  --sbd-blue: #8ddfff;
}

body.sbd-page {
  min-height: 100vh;
  color: var(--sbd-ink);
  background:
    radial-gradient(circle at 14% 12%, rgba(73, 159, 105, .16), transparent 32%),
    radial-gradient(circle at 88% 18%, rgba(137, 70, 144, .13), transparent 29%),
    #07120f;
  overflow-x: hidden;
}

.sbd-page button, .sbd-page a { font: inherit; }
.sbd-page button { -webkit-tap-highlight-color: transparent; }

.sbd-app { width: min(1500px, 100%); margin: 0 auto; padding: 12px; }

.sbd-topbar {
  min-height: 68px;
  display: grid;
  grid-template-columns: minmax(220px, 1fr) auto auto;
  align-items: center;
  gap: 16px;
  padding: 9px 14px;
  border: 1px solid var(--sbd-line);
  border-radius: 15px;
  background: linear-gradient(180deg, rgba(19, 45, 36, .98), rgba(8, 22, 18, .98));
  box-shadow: 0 13px 36px rgba(0, 0, 0, .36), inset 0 1px rgba(255,255,255,.045);
}

.sbd-brand { display: flex; align-items: center; gap: 11px; min-width: 0; }
.sbd-brand > a {
  width: 40px; height: 40px; display: grid; place-items: center;
  color: #e9ffe0; border: 1px solid rgba(255,255,255,.14); border-radius: 11px;
  background: rgba(255,255,255,.05); text-decoration: none; font-size: 29px; line-height: 1;
}
.sbd-brand h1 { color: #c9ff8c; font-size: 22px; line-height: 1.05; letter-spacing: 1px; }
.sbd-brand span { display: block; margin-top: 4px; color: var(--sbd-muted); font-size: 11px; }

.sbd-scoreboard { display: flex; align-items: center; justify-content: center; gap: 6px; flex-wrap: wrap; }
.sbd-scoreboard span {
  min-height: 34px; display: inline-flex; align-items: center; gap: 5px; padding: 6px 9px;
  border: 1px solid rgba(255,255,255,.085); border-radius: 8px; color: #91aa9e;
  background: rgba(0,0,0,.16); font-size: 10px; white-space: nowrap;
}
.sbd-scoreboard b { color: #f1fff0; font-size: 13px; }
.sbd-scoreboard .player b { color: var(--sbd-green); }
.sbd-scoreboard .rival b { color: #ff9994; }

.sbd-actions { display: flex; gap: 5px; }
.sbd-actions button, .sbd-selection button, .sbd-result-actions button {
  min-height: 35px; padding: 6px 10px; border: 1px solid rgba(255,255,255,.13); border-radius: 8px;
  color: #dcece3; background: rgba(255,255,255,.055); cursor: pointer; font-weight: 800;
}
.sbd-info-toggle, .sbd-mobile-hud, .sbd-mobile-settings { display: none; }
.sbd-actions button:hover, .sbd-selection button:hover, .sbd-result-actions button:hover {
  border-color: var(--sbd-green); background: rgba(139,224,107,.1);
}
.sbd-actions button.audio-off { color: #84968d; background: rgba(0,0,0,.18); }
.sbd-page button:disabled { cursor: not-allowed; opacity: .42; filter: grayscale(.35); }

.sbd-layout { display: grid; grid-template-columns: minmax(0, 1fr) 330px; gap: 12px; align-items: start; margin-top: 12px; }

.sbd-arena {
  position: relative; min-width: 0; overflow: hidden; border: 1px solid rgba(172,232,164,.2);
  border-radius: 17px; background: #142e25; box-shadow: 0 18px 50px rgba(0,0,0,.38);
}
#sbdCanvas { display: block; width: 100%; aspect-ratio: 16 / 10; image-rendering: pixelated; touch-action: none; }

.sbd-hint {
  position: absolute; left: 50%; bottom: 8px; z-index: 5; transform: translateX(-50%);
  max-width: calc(100% - 20px); padding: 5px 11px; border: 1px solid rgba(255,255,255,.13);
  border-radius: 999px; color: rgba(235,251,232,.85); background: rgba(5,17,13,.75);
  backdrop-filter: blur(5px); font-size: 10px; white-space: nowrap; pointer-events: none;
}

.sbd-toast {
  position: absolute; left: 50%; top: 14px; z-index: 20; transform: translate(-50%, -10px);
  opacity: 0; padding: 8px 13px; border: 1px solid rgba(191,251,137,.38); border-radius: 9px;
  color: #f1ffe9; background: rgba(8,31,22,.94); box-shadow: 0 9px 25px rgba(0,0,0,.4);
  font-size: 12px; font-weight: 800; pointer-events: none; transition: opacity .16s, transform .16s;
}
.sbd-toast.show { opacity: 1; transform: translate(-50%, 0); }

.sbd-control { display: flex; flex-direction: column; gap: 9px; }
.sbd-card {
  padding: 12px; border: 1px solid var(--sbd-line); border-radius: 13px;
  background: linear-gradient(155deg, rgba(20,45,36,.96), var(--sbd-panel));
  box-shadow: inset 0 1px rgba(255,255,255,.035), 0 8px 24px rgba(0,0,0,.18);
}
.sbd-card small { display: block; color: #68917d; font-size: 9px; font-weight: 900; letter-spacing: .1em; text-transform: uppercase; }
.sbd-card b { display: block; color: #edfaeb; font-size: 13px; }
.sbd-card span, .sbd-card em { color: var(--sbd-muted); font-size: 10px; font-style: normal; }
.sbd-card-head { display: flex; align-items: start; justify-content: space-between; gap: 8px; margin-bottom: 9px; }

.sbd-economy { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.sbd-economy b { margin-top: 3px; color: var(--sbd-gold); font-size: 22px; }
.sbd-economy em { display: block; margin-top: 2px; color: #8cbea0; }
.sbd-primary {
  min-height: 42px; padding: 8px 13px; border: 1px solid rgba(194,248,130,.5) !important;
  border-radius: 9px; color: #102117 !important; background: linear-gradient(180deg,#caf681,#72ce5c) !important;
  box-shadow: inset 0 1px rgba(255,255,255,.45), 0 7px 18px rgba(80,170,70,.22); cursor: pointer; font-weight: 950 !important;
}
.sbd-primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
.sbd-recruit {
  position: relative; min-width: 148px; overflow: hidden; isolation: isolate;
  display: grid; place-items: center; align-content: center; gap: 1px;
  color: #eaffdc !important; background: rgba(22,43,31,.92) !important;
}
.sbd-recruit-fill {
  position: absolute; z-index: -1; inset: 0 auto 0 0; width: var(--sbd-recruit-progress,0%);
  background: linear-gradient(90deg,#4f9f4d,#a5ed68); transition: width .18s linear;
}
.sbd-recruit span { color: inherit; font-size: 13px; font-weight: 950; }
.sbd-recruit small { color: rgba(233,255,218,.68); font-size: 7px; letter-spacing: 0; text-transform: none; }
.sbd-recruit.ready { color: #102117 !important; box-shadow: 0 0 0 1px rgba(203,255,126,.52), 0 0 20px rgba(135,225,88,.22); }
.sbd-recruit.ready small { color: rgba(20,48,24,.7); }
.sbd-page .sbd-recruit:disabled { opacity: 1; filter: none; cursor: not-allowed; }

.sbd-bench { display: grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap: 5px; }
.sbd-bench-slot {
  position: relative; min-width: 0; aspect-ratio: .82; display: grid; place-items: center; padding: 3px;
  border: 1px dashed rgba(255,255,255,.13); border-radius: 8px; color: #60776c;
  background: rgba(0,0,0,.16); cursor: pointer; touch-action: none;
}
.sbd-bench-slot.filled { border-style: solid; border-color: rgba(190,235,174,.22); color: #edf9ea; background: rgba(255,255,255,.045); }
.sbd-bench-slot.selected { border-color: #d3ff8c; box-shadow: 0 0 0 2px rgba(169,236,108,.18), inset 0 0 16px rgba(132,224,93,.11); }
.sbd-bench-slot.drop-target { border-color: #ffe47d; background: rgba(255,217,104,.13); box-shadow: inset 0 0 18px rgba(255,219,112,.15); }
.sbd-bench-slot.merge-target { border-color: #bfff78; background: rgba(152,239,103,.18); box-shadow: 0 0 0 2px rgba(166,246,102,.18), inset 0 0 22px rgba(150,239,99,.2); }
.sbd-bench-slot .glyph { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 7px; font-size: 17px; font-weight: 950; }
.sbd-bench-slot small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; letter-spacing: 0; text-transform: none; font-size: 8px; }
.sbd-bench-slot sup { position: absolute; right: 3px; top: 2px; color: #ffe17a; font-size: 8px; }
.sbd-bench.refreshing .sbd-bench-slot { animation: sbd-bench-refresh .28s ease both; }
.sbd-bench.refreshing .sbd-bench-slot:nth-child(2) { animation-delay: .025s; }
.sbd-bench.refreshing .sbd-bench-slot:nth-child(3) { animation-delay: .05s; }
.sbd-bench.refreshing .sbd-bench-slot:nth-child(4) { animation-delay: .075s; }
.sbd-bench.refreshing .sbd-bench-slot:nth-child(5) { animation-delay: .1s; }
@keyframes sbd-bench-refresh { 0% { opacity: .1; transform: translateY(8px) scale(.9); } 100% { opacity: 1; transform: none; } }

.glyph.thorn, .sbd-guide i.thorn { color: #f6d28f; background: rgba(207,139,67,.22); }
.glyph.frost, .sbd-guide i.frost { color: #b8efff; background: rgba(88,182,215,.2); }
.glyph.flame, .sbd-guide i.flame { color: #ff9a71; background: rgba(224,92,60,.2); }
.glyph.arc, .sbd-guide i.arc { color: #e0c1ff; background: rgba(145,92,202,.22); }
.glyph.garden, .sbd-guide i.garden { color: #a9ed7f; background: rgba(86,172,78,.22); }
.glyph.drill, .sbd-guide i.drill { color: #ffd581; background: rgba(194,141,50,.2); }
.glyph.fragment, .sbd-formulas i { color: #ffeaa6; background: rgba(198,151,64,.18); }
.glyph.pen, .sbd-guide i.pen { color: #9fd8ff; background: rgba(84,140,206,.22); }
.glyph.writ, .sbd-guide i.writ { color: #ffc9e2; background: rgba(196,96,150,.2); }
.glyph.guardian { color: #eaffbb; background: linear-gradient(135deg,rgba(114,209,108,.3),rgba(100,157,218,.24)); }

.sbd-selection { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; margin-top: 9px; padding-top: 8px; border-top: 1px solid rgba(255,255,255,.07); }
.sbd-selection span { display: block; margin-top: 2px; line-height: 1.3; }

.sbd-drag-ghost {
  position: fixed; z-index: 80; width: 44px; height: 44px; display: grid; place-items: center;
  border: 2px solid #d8ff91; border-radius: 11px; color: #f4ffe8; background: rgba(12,35,26,.94);
  box-shadow: 0 10px 24px rgba(0,0,0,.45), 0 0 18px rgba(178,241,116,.25);
  font-size: 17px; font-weight: 950; pointer-events: none; transform: translate(-50%,-50%);
}
.sbd-dragging, .sbd-dragging * { cursor: grabbing !important; }
.sbd-dragging .sbd-bench-slot { touch-action: none; }

.sbd-formulas { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.sbd-formulas > span { display: grid; grid-template-columns: 25px 10px 25px 1fr; align-items: center; gap: 2px; padding: 6px; border: 1px solid rgba(255,255,255,.07); border-radius: 8px; background: rgba(0,0,0,.13); }
.sbd-formulas i { width: 24px; height: 24px; display: grid; place-items: center; border-radius: 6px; font-style: normal; font-weight: 900; }
.sbd-formulas b { font-size: 10px; }
.sbd-formulas small { grid-column: 4; letter-spacing: 0; text-transform: none; font-size: 7px; }

.sbd-duel-info { display: grid; grid-template-columns: 1fr; gap: 8px; }
.sbd-duel-info span { display: block; margin-top: 3px; }
.sbd-ai-log { min-height: 29px; padding: 6px 8px; border-left: 2px solid #b66d8d; color: #b99bab; background: rgba(111,47,78,.09); font-size: 9px; line-height: 1.4; }

.sbd-guide { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 5px 7px; }
.sbd-guide span { display: flex; align-items: center; gap: 5px; }
.sbd-guide i { width: 22px; height: 22px; display: grid; place-items: center; border-radius: 5px; font-style: normal; font-weight: 900; }

.sbd-overlay {
  position: absolute; inset: 0; z-index: 15; display: none; place-items: center; padding: 18px;
  background: rgba(5,15,12,.82); backdrop-filter: blur(7px);
}
.sbd-overlay.show { display: grid; }
.sbd-menu-panel, .sbd-result-panel {
  width: min(610px,100%); max-height: calc(100% - 12px); overflow-y: auto; padding: 22px;
  border: 1px solid rgba(190,241,159,.2); border-radius: 16px;
  background: linear-gradient(160deg,rgba(22,54,41,.98),rgba(8,26,20,.99)); box-shadow: 0 22px 60px rgba(0,0,0,.5);
}
.sbd-kicker { color: #6eaf85; font-size: 9px; font-weight: 950; letter-spacing: .18em; }
.sbd-menu-panel h2, .sbd-result-panel h2 { margin-top: 5px; color: #d8ff9f; font-size: 27px; }
.sbd-menu-panel > p, .sbd-result-panel > p { margin-top: 6px; color: #91aa9c; font-size: 11px; line-height: 1.55; }
.sbd-rules { display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 6px; margin: 14px 0; }
.sbd-rules span { padding: 8px; border: 1px solid rgba(255,255,255,.075); border-radius: 8px; color: #8fa99a; background: rgba(0,0,0,.13); font-size: 9px; line-height: 1.4; }
.sbd-rules b { display: block; margin-bottom: 2px; color: #dbf8d2; font-size: 11px; }
.sbd-opponent-preview { display: flex; align-items: center; gap: 10px; padding: 10px; border: 1px solid rgba(220,119,165,.17); border-radius: 10px; background: rgba(100,40,70,.09); }
.sbd-opponent-preview i { width: 43px; height: 43px; display: grid; place-items: center; border-radius: 50%; color: #ffc4dd; background: radial-gradient(circle,#883e62,#32172a); font-size: 23px; font-style: normal; }
.sbd-opponent-preview small, .sbd-opponent-preview span { display: block; color: #a58395; font-size: 8px; }
.sbd-opponent-preview b { display: block; margin: 2px 0; color: #ffd7e6; font-size: 13px; }
.sbd-menu-actions, .sbd-result-actions { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 14px; }
.sbd-menu-actions a, .sbd-result-actions a { padding: 8px 11px; color: #9dc3aa; text-decoration: none; font-size: 10px; }

.sbd-result-panel { width: min(460px,100%); text-align: center; }
.sbd-result-icon { width: 68px; height: 68px; display: grid; place-items: center; margin: 0 auto 9px; border-radius: 50%; color: #15301d; background: radial-gradient(circle,#efffb6,#82d665 64%,#275d3c 66%); font-size: 32px; }
.sbd-result-panel.lose .sbd-result-icon { color: #421b25; background: radial-gradient(circle,#ffd0d4,#d66376 64%,#682638 66%); }
.sbd-result-stats { display: grid; grid-template-columns: repeat(3,1fr); gap: 6px; margin: 14px 0; }
.sbd-result-stats span { padding: 9px 5px; border: 1px solid rgba(255,255,255,.075); border-radius: 8px; color: #7e9a8b; background: rgba(0,0,0,.14); font-size: 8px; }
.sbd-result-stats b { display: block; margin-top: 3px; color: #f0faed; font-size: 15px; }

@media (max-width: 1120px) {
  .sbd-layout { grid-template-columns: minmax(0,1fr) 290px; }
  .sbd-card { padding: 10px; }
  .sbd-scoreboard span { padding-inline: 6px; }
}

@media (max-width: 840px) {
  body.sbd-page { min-height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
  .sbd-app { padding: 5px; }
  .sbd-topbar { min-height: 44px; grid-template-columns: 1fr auto; gap: 5px; padding: 5px 6px; border-radius: 10px; }
  .sbd-brand h1 { font-size: 17px; }
  .sbd-brand span { display: none; }
  .sbd-brand { gap: 7px; }
  .sbd-brand > a { width: 32px; height: 32px; border-radius: 9px; }
  .sbd-actions { gap: 3px; }
  .sbd-actions button { min-height: 31px; padding: 4px 7px; font-size: 9px; }
  .sbd-actions #sbdMusic, .sbd-actions #sbdSfx { display: none; }
  .sbd-info-toggle { display: inline-block; }
  .sbd-scoreboard { display: none; }
  .sbd-layout { display: block; margin-top: 5px; }
  .sbd-arena { border-radius: 10px; }
  #sbdCanvas { width: 100%; height: auto; aspect-ratio: auto; }
  .sbd-mobile-hud {
    position: absolute; inset: 6px 6px auto; z-index: 6; display: grid;
    grid-template-columns: 1fr auto 1fr; align-items: center; gap: 4px; pointer-events: none;
  }
  .sbd-mobile-hud span, .sbd-mobile-hud strong {
    min-height: 25px; display: flex; align-items: center; justify-content: center; gap: 4px;
    padding: 4px 7px; border: 1px solid rgba(255,255,255,.12); border-radius: 999px;
    color: #b6c8be; background: rgba(5,16,13,.78); backdrop-filter: blur(5px); font-size: 8px;
  }
  .sbd-mobile-hud strong { color: #f0ffe8; font-size: 10px; }
  .sbd-mobile-hud b { color: #fff; font-size: 12px; }
  .sbd-mobile-hud .rival b { color: #ff9dbd; }
  .sbd-mobile-hud .player b { color: #c9ff8d; }
  .sbd-control {
    position: relative; z-index: 10; left: auto; right: auto; bottom: auto;
    display: flex; flex-direction: column; gap: 5px; max-height: none; margin: 5px 0 0;
    padding: 5px; border: 1px solid rgba(177,237,174,.16); border-radius: 12px;
    background: rgba(6,20,15,.94); box-shadow: 0 10px 28px rgba(0,0,0,.25); overflow: visible;
  }
  .sbd-card { padding: 7px; border-radius: 9px; }
  .sbd-bench-card { order: 1; }
  .sbd-economy { order: 2; min-height: 48px; padding: 6px 8px; }
  .sbd-formula-card { order: 3; }
  .sbd-duel-info { order: 4; }
  .sbd-guide { order: 5; }
  .sbd-mobile-settings { order: 6; }
  .sbd-bench-card { border-radius: 10px 10px 4px 4px; border-bottom-color: rgba(177,237,174,.08); }
  .sbd-economy { margin-top: -5px; border-radius: 4px 4px 10px 10px; }
  .sbd-bench-card .sbd-card-head { margin-bottom: 4px; }
  .sbd-bench-card .sbd-card-head small { display: none; }
  .sbd-bench-card .sbd-card-head b { font-size: 10px; }
  .sbd-bench-slot { height: 54px; aspect-ratio: auto; border-radius: 7px; }
  .sbd-page .sbd-bench-slot:disabled { opacity: .72; }
  .sbd-bench-slot .glyph { width: 28px; height: 28px; font-size: 15px; }
  .sbd-bench-slot small { font-size: 7px; }
  .sbd-selection { display: none; }
  .sbd-economy small { display: none; }
  .sbd-economy b { margin: 0; font-size: 18px; }
  .sbd-economy em { margin: 0; font-size: 8px; }
  .sbd-economy .sbd-primary { min-width: 148px; min-height: 44px; font-size: 15px; }
  .sbd-economy .sbd-recruit span { font-size: 15px; }
  .sbd-economy .sbd-recruit small { display: block; font-size: 8px; }
  .sbd-formula-card, .sbd-duel-info, .sbd-guide, .sbd-mobile-settings { display: none; }
  .sbd-info-open .sbd-control { overflow: visible; }
  .sbd-info-open .sbd-formula-card, .sbd-info-open .sbd-duel-info,
  .sbd-info-open .sbd-guide, .sbd-info-open .sbd-mobile-settings { display: grid; flex: 0 0 auto; }
  .sbd-info-open .sbd-guide { grid-template-columns: repeat(3,minmax(0,1fr)); }
  .sbd-mobile-settings { grid-template-columns: auto auto 1fr; align-items: center; gap: 6px; }
  .sbd-mobile-settings button {
    min-height: 34px; padding: 5px 9px; border: 1px solid rgba(255,255,255,.13); border-radius: 8px;
    color: #dcece3; background: rgba(255,255,255,.055); font-weight: 800;
  }
  .sbd-mobile-settings span { justify-self: end; }
  .sbd-overlay { padding: 8px; align-items: start; }
  .sbd-menu-panel, .sbd-result-panel { margin: auto 0; padding: 14px; border-radius: 12px; }
  .sbd-menu-panel h2 { font-size: 22px; }
  .sbd-hint { bottom: 4px; padding: 3px 7px; font-size: 8px; }
}

@media (max-width: 500px) {
  .sbd-rules { grid-template-columns: 1fr 1fr; }
  .sbd-menu-panel > p { font-size: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .sbd-toast, .sbd-primary { transition: none; }
}
