:root {
  color-scheme: light;
  --page: #edf1f4;
  --panel: #ffffff;
  --ink: #16202a;
  --muted: #617080;
  --line: #d7dee5;
  --accent: #168f9e;
  --accent-strong: #0a6174;
  --warm: #f0b95c;
  --shadow: 0 20px 48px rgba(20, 32, 43, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(22, 143, 158, 0.08) 1px, transparent 1px),
    linear-gradient(0deg, rgba(22, 143, 158, 0.07) 1px, transparent 1px),
    var(--page);
  background-size: 28px 28px;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Microsoft YaHei", sans-serif;
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

[hidden] {
  display: none !important;
}

.app-shell {
  min-height: 100vh;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 18px 28px;
  border-bottom: 1px solid rgba(115, 128, 143, 0.25);
  background: rgba(237, 241, 244, 0.92);
  backdrop-filter: blur(14px);
}

.brand-block h1,
.preview-toolbar h2 {
  margin: 2px 0 0;
  font-size: clamp(22px, 2.5vw, 34px);
  line-height: 1.05;
  letter-spacing: 0;
}

.eyebrow {
  margin: 0;
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0;
  text-transform: uppercase;
}

.top-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
}

.studio-nav {
  display: inline-flex;
  gap: 6px;
  padding: 4px;
  border: 1px solid #cbd6df;
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.7);
}

.view-tab {
  min-height: 34px;
  padding: 0 14px;
  border: 0;
  border-radius: 6px;
  color: #38505c;
  background: transparent;
  font-weight: 900;
}

.view-tab.is-active {
  color: #fff;
  background: var(--accent-strong);
}

.tool-button,
.icon-button {
  display: inline-flex;
  min-height: 38px;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border: 1px solid #c8d3dc;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
  box-shadow: 0 8px 20px rgba(24, 36, 48, 0.08);
}

.tool-button {
  padding: 0 12px;
  font-weight: 800;
}

.icon-button {
  width: 40px;
  padding: 0;
}

.tool-button.primary {
  border-color: var(--accent-strong);
  color: #fff;
  background: var(--accent-strong);
}

.tool-button.is-saved {
  border-color: #207b4a;
  color: #fff;
  background: #207b4a;
}

.tool-button svg,
.icon-button svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(330px, 430px) minmax(360px, 1fr);
  gap: 24px;
  align-items: start;
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.library-page,
.battle-page {
  width: min(1760px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.editor-panel,
.preview-panel {
  border: 1px solid rgba(115, 128, 143, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.editor-panel {
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 112px);
  overflow: auto;
  padding: 16px;
}

.control-section {
  display: grid;
  gap: 12px;
  padding: 14px;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: #fbfcfd;
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 4px;
  border-bottom: 1px solid #e3e9ee;
  font-size: 14px;
  font-weight: 900;
}

.section-code {
  color: #8995a3;
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 12px;
}

label {
  display: grid;
  gap: 6px;
  color: #3d4b58;
  font-size: 12px;
  font-weight: 800;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid #cbd6df;
  border-radius: 8px;
  color: var(--ink);
  background: #fff;
}

input,
select {
  padding: 0 10px;
}

textarea {
  resize: vertical;
  padding: 9px 10px;
  line-height: 1.45;
}

input[type="range"] {
  padding: 0;
  accent-color: var(--accent-strong);
}

.field-grid {
  display: grid;
  gap: 10px;
}

.field-grid.two {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.field-grid.three {
  grid-template-columns: 0.7fr 1.4fr 0.7fr;
}

.field-grid.four,
.attribute-value-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.attribute-value-grid {
  display: grid;
  gap: 8px;
}

.subsection-label {
  color: #526372;
  font-size: 12px;
  font-weight: 900;
}

.attribute-value-grid input,
.battle-stat-grid input {
  min-height: 34px;
  padding: 0 8px;
}

.battle-prompt-hints {
  display: grid;
  gap: 6px;
  padding: 10px 12px;
  border: 1px solid #d7e1e8;
  border-radius: 8px;
  color: #415261;
  background: #f7fafc;
  font-size: 12px;
  font-weight: 800;
  line-height: 1.45;
}

.swatch-row,
.preset-grid {
  display: grid;
  gap: 8px;
}

.swatch-row {
  grid-template-columns: repeat(8, minmax(0, 1fr));
}

.swatch,
.preset-grid button {
  min-height: 40px;
  border: 1px solid rgba(28, 41, 54, 0.16);
  border-radius: 8px;
  color: #0d1a22;
  font-weight: 900;
  background: #fff;
}

.swatch {
  position: relative;
  overflow: hidden;
}

.swatch::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.88;
}

.swatch span {
  position: relative;
  z-index: 1;
}

.swatch.is-active,
.preset-grid button.is-active {
  outline: 3px solid rgba(10, 97, 116, 0.25);
  border-color: var(--accent-strong);
}

.spark::before {
  background: linear-gradient(135deg, #f7d257, #f08d39);
}

.aqua::before {
  background: linear-gradient(135deg, #78d6ff, #2d77c8);
}

.flora::before {
  background: linear-gradient(135deg, #9be870, #209966);
}

.ember::before {
  background: linear-gradient(135deg, #ff956f, #c63338);
}

.dusk::before {
  background: linear-gradient(135deg, #7a87a8, #252c46);
}

.lust::before {
  background: linear-gradient(135deg, #ff9acb, #9c2466);
}

.normal::before {
  background: linear-gradient(135deg, #f7f3e8, #a7a396);
}

.light::before {
  background: linear-gradient(135deg, #fff6a8, #5ec8ff);
}

.preset-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.file-drop {
  align-items: center;
  min-height: 62px;
  justify-items: center;
  border: 1px dashed #9fb1c1;
  border-radius: 8px;
  color: var(--accent-strong);
  background: #f6fbfc;
}

.file-drop input {
  display: none;
}

.file-drop span {
  font-size: 14px;
  font-weight: 900;
}

.switch-line {
  display: flex;
  align-items: center;
  gap: 10px;
}

.switch-line input {
  width: 18px;
  min-height: 18px;
  accent-color: var(--accent-strong);
}

.move-block {
  display: grid;
  gap: 10px;
  padding-top: 10px;
  border-top: 1px solid #e4eaf0;
}

.move-block:first-of-type {
  padding-top: 0;
  border-top: 0;
}

.library-actions {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: end;
}

.library-list {
  display: grid;
  max-height: 260px;
  gap: 8px;
  overflow: auto;
  padding-right: 2px;
}

.library-hero,
.battle-hero,
.library-controls-panel,
.library-group,
.battle-selection-panel,
.battle-start-panel,
.battle-player,
.battle-log-panel {
  border: 1px solid rgba(115, 128, 143, 0.28);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.94);
  box-shadow: var(--shadow);
}

.library-hero,
.battle-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  padding: 18px 20px;
}

.library-hero h2,
.battle-hero h2 {
  margin: 2px 0 0;
  font-size: clamp(24px, 3vw, 38px);
  line-height: 1.05;
}

.library-stat,
.battle-rule {
  min-height: 34px;
  padding: 8px 12px;
  border: 1px solid #cbd6df;
  border-radius: 8px;
  color: #25404a;
  background: #f7fafc;
  font-size: 13px;
  font-weight: 900;
}

.battle-setup {
  display: grid;
  grid-template-columns: repeat(2, minmax(260px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}

.battle-selection-panel,
.battle-start-panel,
.battle-player,
.battle-log-panel {
  display: grid;
  gap: 12px;
  padding: 16px;
}

.battle-start-panel {
  grid-column: 1 / -1;
  grid-template-columns: auto auto minmax(220px, 1fr);
  align-items: center;
}

.battle-start-panel p {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.battle-choice-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  max-height: 260px;
  overflow: auto;
}

.battle-choice {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  padding: 9px 10px;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: #fff;
}

.battle-choice input {
  width: 16px;
  min-height: 16px;
  accent-color: var(--accent-strong);
}

.battle-choice span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battlefield {
  display: grid;
  gap: 14px;
}

.battle-status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 42px;
  padding: 10px 14px;
  border: 1px solid #8fbd70;
  border-radius: 8px;
  background: linear-gradient(135deg, rgba(255, 255, 255, 0.96), rgba(233, 248, 224, 0.94));
}

.battle-status-bar strong {
  color: #17613f;
  font-size: 15px;
}

.battle-status-bar span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
}

.battle-board {
  position: relative;
  display: grid;
  min-height: 920px;
  padding: 26px;
  overflow: hidden;
  border: 6px solid #8dcc69;
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 20%, transparent 80%, rgba(255, 255, 255, 0.14)),
    linear-gradient(180deg, #2c9b67 0 49%, #7d9460 49% 51%, #7fb05c 51% 100%);
  box-shadow: inset 0 0 0 4px rgba(255, 255, 255, 0.42), 0 16px 36px rgba(23, 52, 40, 0.24);
}

.battle-board::before {
  content: "";
  order: 2;
  height: 76px;
  margin: -4px 8px;
  border-top: 3px solid rgba(255, 255, 255, 0.62);
  border-bottom: 3px solid rgba(255, 255, 255, 0.62);
  background:
    radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.9) 0 11px, #83ad62 12px 22px, rgba(255, 255, 255, 0.7) 23px 30px, transparent 31px),
    linear-gradient(90deg, transparent 0 18%, rgba(255, 255, 255, 0.62) 18% 42%, transparent 42% 58%, rgba(255, 255, 255, 0.62) 58% 82%, transparent 82% 100%);
  pointer-events: none;
}

.battle-board::after {
  content: "";
  position: absolute;
  inset: 14px;
  border: 3px solid rgba(255, 255, 255, 0.55);
  border-radius: 6px;
  pointer-events: none;
}

.battle-player {
  position: relative;
  z-index: 1;
  display: grid;
  min-height: 382px;
  gap: 18px;
  padding: 0;
  border: 0;
  background: transparent;
  box-shadow: none;
}

#p2BattlePanel {
  order: 1;
  grid-template-columns: minmax(320px, 1fr) minmax(220px, 1fr) 140px;
  grid-template-areas:
    "hand hand head"
    "roster active head";
  align-items: center;
}

#p1BattlePanel {
  order: 3;
  grid-template-columns: 140px minmax(220px, 1fr) minmax(320px, 1fr);
  grid-template-areas:
    "head active roster"
    "hand hand hand";
  align-items: center;
}

.battle-player-head {
  grid-area: head;
  display: grid;
  gap: 9px;
  align-self: center;
  min-height: 156px;
  padding: 10px;
  border: 2px solid rgba(255, 255, 255, 0.62);
  border-radius: 8px;
  background: rgba(212, 236, 178, 0.82);
  box-shadow: inset 0 0 0 2px rgba(71, 129, 70, 0.2);
}

.battle-player-head::before {
  content: "牌堆";
  display: grid;
  width: 58px;
  height: 78px;
  place-items: center;
  justify-self: center;
  border: 3px solid #f0d149;
  border-radius: 6px;
  color: #fff7ae;
  background:
    radial-gradient(circle at 50% 50%, #f1672d 0 9px, #2b72c9 10px 25px, transparent 26px),
    linear-gradient(135deg, #2356a8, #163b76);
  font-size: 12px;
  font-weight: 900;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.34);
}

.battle-player-head h3 {
  margin: 0;
  color: #1f4e36;
  font-size: 16px;
  text-align: center;
}

.battle-player-head label {
  display: grid;
  gap: 5px;
  color: #335442;
  font-size: 11px;
  font-weight: 900;
}

.battle-player-head select {
  min-height: 34px;
  padding: 0 8px;
  border: 1px solid rgba(50, 96, 60, 0.34);
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.82);
  color: #1f3e2f;
  font-size: 12px;
  font-weight: 900;
}

.battle-active {
  grid-area: active;
  display: grid;
  width: min(254px, 100%);
  min-height: auto;
  gap: 8px;
  align-content: start;
  justify-self: center;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
}

#p2BattlePanel .battle-active {
  align-self: end;
  transform: translateY(8px);
}

#p1BattlePanel .battle-active {
  align-self: start;
  transform: translateY(-8px);
}

.battle-active > strong {
  padding: 7px 8px 0;
  border-radius: 6px 6px 0 0;
  color: #142015;
  background: rgba(255, 255, 255, 0.82);
  font-size: 15px;
  line-height: 1.2;
  text-align: center;
}

.battle-active > span {
  padding: 0 8px;
  color: #203e2d;
  background: rgba(255, 255, 255, 0.82);
  font-size: 12px;
  font-weight: 900;
  text-align: center;
}

.battle-active > small {
  display: block;
  padding: 0 8px 6px;
  border-radius: 0 0 6px 6px;
  color: #244234;
  background: rgba(255, 255, 255, 0.82);
  font-size: 11px;
  font-weight: 900;
  line-height: 1.25;
  text-align: center;
}

.battle-active > strong,
.battle-active > span,
.battle-active > .battle-hp,
.battle-active > small {
  display: none;
}

.battle-hp {
  height: 10px;
  overflow: hidden;
  border: 1px solid rgba(34, 67, 40, 0.24);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.68);
}

.battle-hp i {
  display: block;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #1a9b72, #f0b95c);
}

.battle-move-actions {
  display: grid;
  gap: 6px;
}

.battle-move-row {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px;
  border-radius: 7px;
  background: rgba(255, 255, 255, 0.84);
}

.battle-move-row b {
  flex: 1 0 100%;
  overflow: hidden;
  color: #20372c;
  font-size: 10px;
  line-height: 1.2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-move-row button {
  min-height: 24px;
  padding: 0 6px;
  border: 1px solid rgba(33, 88, 58, 0.26);
  border-radius: 6px;
  color: #1f4c35;
  background: #f3ffe9;
  font-size: 11px;
  font-weight: 900;
}

.battle-move-row button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
}

.battle-roster {
  grid-area: roster;
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  border: 2px dashed rgba(255, 255, 255, 0.58);
  border-radius: 8px;
  background: rgba(255, 255, 255, 0.12);
}

.battle-roster-chip {
  display: grid;
  width: 86px;
  min-height: 108px;
  align-content: center;
  padding: 8px;
  border: 3px solid rgba(235, 240, 218, 0.86);
  border-radius: 8px;
  color: #21392d;
  background: linear-gradient(160deg, #f8f3ca, #f4b45a 46%, #5e9d76);
  font-size: 12px;
  font-weight: 900;
  line-height: 1.35;
  text-align: center;
  box-shadow: 0 8px 14px rgba(24, 58, 36, 0.18);
}

.battle-roster-chip.is-dead {
  color: #8c2d28;
  background: linear-gradient(160deg, #f3e7e5, #c9bbb8);
  text-decoration: line-through;
  opacity: 0.68;
}

.battle-hand {
  grid-area: hand;
  display: flex;
  min-width: 0;
  gap: 12px;
  overflow-x: auto;
  padding: 10px 4px 4px;
}

.battle-hand-group {
  display: flex;
  flex: 0 0 auto;
  align-items: flex-end;
  gap: 8px;
  min-width: 0;
  padding: 8px 10px;
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 8px;
  background: rgba(250, 255, 244, 0.72);
}

.battle-hand-group h4 {
  width: 44px;
  margin: 0;
  color: #24452f;
  font-size: 12px;
  line-height: 1.2;
  writing-mode: vertical-rl;
}

.battle-hand-card {
  display: flex;
  position: relative;
  flex: 0 0 178px;
  width: 178px;
  min-height: auto;
  flex-direction: column;
  justify-content: flex-start;
  gap: 6px;
  overflow: visible;
  padding: 0;
  border: 0;
  border-radius: 8px;
  background: transparent;
  box-shadow: none;
  scroll-snap-align: start;
}

.battle-hand-card::before {
  display: none;
}

.battle-hand-kind {
  align-self: flex-start;
  padding: 3px 7px;
  border-radius: 999px;
  color: #fff;
  background: rgba(19, 48, 38, 0.78);
  font-size: 10px;
  font-weight: 900;
}

.battle-card-face {
  display: grid;
  position: relative;
  isolation: isolate;
  width: 100%;
  aspect-ratio: 744 / 1039;
  grid-template-rows: auto auto auto 1fr auto;
  gap: 5px;
  overflow: hidden;
  padding: 8px;
  border: 3px solid #dfc95d;
  border-radius: 8px;
  background:
    linear-gradient(145deg, var(--card-light, #fff2a8), var(--card-mid, #ffffff) 46%, var(--card-dark, #d9edf5));
  box-shadow: 0 10px 18px rgba(22, 50, 36, 0.22);
}

.battle-card-face::before {
  content: "";
  position: absolute;
  inset: 5px;
  z-index: -1;
  border-radius: 6px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.46), transparent 26%, rgba(16, 30, 26, 0.42)),
    radial-gradient(circle at 28% 12%, rgba(255, 255, 255, 0.62), transparent 24%);
}

.battle-card-face::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: -1;
  background:
    linear-gradient(115deg, transparent 8%, rgba(255, 255, 255, 0.26) 28%, transparent 48%),
    linear-gradient(180deg, transparent, rgba(0, 0, 0, 0.12));
  pointer-events: none;
}

.battle-card-face-art {
  position: absolute;
  inset: 7px;
  z-index: -2;
  border-radius: 6px;
  background:
    radial-gradient(circle at 50% 35%, rgba(255, 255, 255, 0.9), transparent 24%),
    linear-gradient(145deg, var(--card-light, #f6d866), var(--card-mid, #f28a4d), var(--card-dark, #3f6e91));
  background-position: center;
  background-size: cover;
  transform: scale(1.03);
}

.battle-card-face-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 5px;
}

.battle-card-face-head span {
  max-width: 48%;
  overflow: hidden;
  padding: 3px 5px;
  border: 1px solid rgba(255, 255, 255, 0.7);
  border-radius: 999px;
  color: #17231f;
  background: rgba(255, 255, 255, 0.78);
  font-size: 9px;
  font-weight: 900;
  line-height: 1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-card-face-name {
  overflow: hidden;
  padding: 5px 6px;
  border-radius: 6px;
  color: #101a17;
  background: rgba(255, 255, 255, 0.82);
  font-size: 14px;
  font-weight: 1000;
  line-height: 1.14;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-card-face-stats {
  overflow: hidden;
  padding: 4px 6px;
  border-radius: 5px;
  color: #1b3128;
  background: rgba(255, 255, 255, 0.74);
  font-size: 10px;
  font-weight: 900;
  line-height: 1.15;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-card-face-text {
  display: -webkit-box;
  min-height: 42px;
  margin: auto 0 0;
  overflow: hidden;
  padding: 6px;
  border-radius: 6px;
  color: #1a2c24;
  background: rgba(255, 255, 255, 0.78);
  font-size: 10px;
  font-weight: 850;
  line-height: 1.32;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
}

.battle-active .battle-card-face {
  width: min(254px, 100%);
}

.battle-hand-card strong,
.battle-hand-card small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.battle-hand-card small {
  color: #4b5b52;
  display: -webkit-box;
  min-height: 42px;
  font-size: 11px;
  font-weight: 800;
  line-height: 1.35;
  white-space: normal;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
}

.battle-card-values {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: auto;
}

.battle-card-values span {
  padding: 3px 5px;
  border: 1px solid rgba(35, 75, 53, 0.16);
  border-radius: 6px;
  color: #1f4c35;
  background: rgba(243, 255, 233, 0.86);
  font-size: 10px;
  font-weight: 900;
  line-height: 1.1;
}

#p2BattlePanel .battle-hand {
  justify-content: center;
  overflow: hidden;
  padding-top: 0;
}

#p2BattlePanel .battle-hand-group {
  align-items: center;
  padding: 0;
  border: 0;
  background: transparent;
}

#p2BattlePanel .battle-hand-group h4 {
  width: auto;
  margin-right: 8px;
  color: rgba(255, 255, 255, 0.92);
  writing-mode: horizontal-tb;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.22);
}

.battle-hand-card.is-hidden-card {
  flex-basis: 54px;
  width: 54px;
  min-height: 76px;
  margin-left: -18px;
  padding: 6px;
  border: 2px solid #f1d451;
  background:
    radial-gradient(circle at 50% 50%, #f36c34 0 8px, #f8e25f 9px 13px, #265cae 14px 24px, transparent 25px),
    linear-gradient(135deg, #2c76d2, #102f73);
  box-shadow: 0 7px 12px rgba(15, 42, 38, 0.24);
}

.battle-hand-card.is-hidden-card:first-of-type {
  margin-left: 0;
}

.battle-hand-card.is-hidden-card strong,
.battle-hand-card.is-hidden-card small {
  opacity: 0;
}

.battle-card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.battle-card-actions button {
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid rgba(33, 88, 58, 0.26);
  border-radius: 8px;
  color: #1f4c35;
  background: #f3ffe9;
  font-size: 12px;
  font-weight: 900;
}

.battle-card-actions button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.battle-log {
  display: grid;
  max-height: 220px;
  gap: 6px;
  overflow: auto;
}

.battle-log div,
.battle-empty {
  padding: 8px 10px;
  border-radius: 8px;
  color: #405260;
  background: #f7fafc;
  font-size: 13px;
  font-weight: 800;
}

.library-controls-panel {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(150px, 220px) minmax(220px, 1fr);
  gap: 12px;
  margin-bottom: 16px;
  padding: 16px;
}

.library-groups {
  display: grid;
  gap: 16px;
}

.library-group {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.library-group-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 10px;
  border-bottom: 1px solid #e3e9ee;
}

.library-group-header h3 {
  margin: 0;
  font-size: 20px;
  line-height: 1.2;
}

.library-group-header span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 900;
}

.library-kind-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(150px, 1fr));
  gap: 10px;
}

.library-kind-column {
  display: grid;
  align-content: start;
  gap: 8px;
  min-width: 0;
  padding: 10px;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: #fbfcfd;
}

.library-kind-column h4 {
  margin: 0;
  color: #344653;
  font-size: 13px;
  line-height: 1.25;
}

.library-kind-empty {
  display: grid;
  min-height: 48px;
  place-items: center;
  border: 1px dashed #c8d3dc;
  border-radius: 8px;
  color: #8a97a5;
  background: #fff;
  font-size: 12px;
  font-weight: 800;
}

.library-empty {
  display: grid;
  min-height: 54px;
  place-items: center;
  border: 1px dashed #b9c8d4;
  border-radius: 8px;
  color: var(--muted);
  background: #f6fbfc;
  font-size: 13px;
  font-weight: 800;
}

.library-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 10px;
  border: 1px solid #d9e1e8;
  border-radius: 8px;
  background: #fff;
}

.library-card-body {
  display: grid;
  min-width: 0;
  gap: 3px;
}

.library-card-body strong,
.library-card-body span,
.library-card-body small {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-card-body strong {
  color: var(--ink);
  font-size: 14px;
}

.library-card-body span {
  color: #536170;
  font-size: 12px;
  font-weight: 800;
}

.library-card-body small {
  color: #7a8794;
  font-size: 12px;
  font-weight: 700;
}

.library-card-actions {
  display: flex;
  gap: 6px;
}

.mini-button,
.mini-select {
  min-height: 32px;
  padding: 0 9px;
  border: 1px solid #c8d3dc;
  border-radius: 8px;
  color: #25404a;
  background: #f7fafc;
  font-size: 12px;
  font-weight: 900;
}

.mini-select {
  width: auto;
  min-width: 94px;
  max-width: 100%;
}

.mini-button.danger {
  border-color: #e4bebc;
  color: #8c2d28;
  background: #fff7f6;
}

.preview-panel {
  position: sticky;
  top: 94px;
  display: grid;
  gap: 18px;
  padding: 20px;
}

.preview-toolbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}

.status-chips {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.status-chips span {
  min-height: 30px;
  padding: 6px 10px;
  border: 1px solid #cbd6df;
  border-radius: 8px;
  color: #25404a;
  background: #f7fafc;
  font-size: 12px;
  font-weight: 900;
}

.canvas-frame {
  display: grid;
  place-items: center;
  min-height: 0;
  padding: clamp(12px, 2vw, 22px);
  border: 1px solid #d6e0e8;
  border-radius: 8px;
  background:
    linear-gradient(135deg, rgba(255, 255, 255, 0.82), rgba(255, 255, 255, 0.46)),
    #dfe7ed;
}

canvas {
  width: min(100%, 520px);
  height: auto;
  border-radius: 18px;
  box-shadow: 0 24px 54px rgba(18, 27, 36, 0.28);
}

@media (max-width: 980px) {
  .topbar,
  .preview-toolbar {
    align-items: stretch;
    flex-direction: column;
  }

  .top-actions,
  .studio-nav,
  .status-chips {
    justify-content: flex-start;
  }

  .workspace {
    grid-template-columns: 1fr;
    padding: 14px;
  }

  .library-page,
  .battle-page {
    padding: 14px;
  }

  .library-controls-panel,
  .battle-setup,
  .battle-board,
  .battle-start-panel {
    grid-template-columns: 1fr;
  }

  .library-kind-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .field-grid.four,
  .attribute-value-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .editor-panel,
  .preview-panel {
    position: static;
    max-height: none;
  }

  .battle-board {
    min-height: auto;
    padding: 12px;
  }

  .battle-board::before {
    height: 54px;
    margin: 2px 4px;
  }

  #p1BattlePanel,
  #p2BattlePanel {
    grid-template-columns: 1fr;
    grid-template-areas:
      "head"
      "active"
      "roster"
      "hand";
    min-height: auto;
  }

  .battle-player-head {
    min-height: auto;
  }

  .battle-player-head::before {
    display: none;
  }

  .battle-roster-chip {
    width: 78px;
    min-height: 96px;
  }

  .battle-active {
    min-height: auto;
  }
}

@media (max-width: 620px) {
  .topbar {
    padding: 14px;
  }

  .field-grid.two,
  .field-grid.three,
  .field-grid.four,
  .attribute-value-grid,
  .library-actions {
    grid-template-columns: 1fr;
  }

  .library-card {
    grid-template-columns: 1fr;
  }

  .library-card-actions {
    justify-content: flex-start;
  }

  .swatch-row {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .preset-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .library-hero,
  .battle-hero,
  .battle-status-bar {
    align-items: flex-start;
    flex-direction: column;
  }

  .library-kind-grid,
  .battle-choice-list,
  .battle-player-head {
    grid-template-columns: 1fr;
  }

  .battle-hand-group {
    padding: 7px;
  }

  .battle-hand-card {
    flex-basis: 148px;
    width: 148px;
    min-height: 214px;
  }

  .battle-hand-group h4 {
    width: 34px;
    font-size: 11px;
  }
}
