:root {
  color-scheme: light;
  --bg: #eef1f4;
  --panel: #ffffff;
  --ink: #111111;
  --muted: #5f6872;
  --line: #c7ccd2;
  --accent: #2f9f52;
  --accent-strong: #16783a;
  --focus: #2457d6;
  --shadow: 0 18px 48px rgba(17, 24, 39, 0.13);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Yu Gothic", "Noto Sans JP", sans-serif;
}

button,
input,
select {
  font: inherit;
}

button {
  min-height: 38px;
  border: 1px solid #aab2bc;
  border-radius: 8px;
  background: #ffffff;
  color: #18202a;
  cursor: pointer;
}

button:hover {
  border-color: #687482;
}

button:focus-visible,
input:focus-visible {
  outline: 3px solid rgba(36, 87, 214, 0.24);
  outline-offset: 2px;
}

button.primary {
  border-color: #0f6c35;
  background: linear-gradient(180deg, #34c466 0%, #188946 100%);
  color: #ffffff;
  font-weight: 800;
  box-shadow:
    0 10px 20px rgba(22, 120, 58, 0.24),
    inset 0 1px 0 rgba(255, 255, 255, 0.28);
}

button.primary:hover {
  border-color: #0a5b2b;
  background: linear-gradient(180deg, #3ad46f 0%, #147c3d 100%);
}

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

.workspace {
  display: grid;
  grid-template-columns: minmax(390px, 520px) minmax(620px, 1fr);
  gap: 18px;
  align-items: start;
}

.editor,
.preview-pane {
  background: var(--panel);
  border: 1px solid #dde1e6;
  box-shadow: var(--shadow);
}

.editor {
  max-height: calc(100vh - 36px);
  overflow: auto;
  padding: 18px;
}

.editor-top {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
  flex-wrap: wrap;
}

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

.top-actions button:not(.icon-button) {
  min-width: 86px;
  padding: 0 12px;
  white-space: nowrap;
}

.editor h1 {
  margin: 0;
  font-size: 24px;
  line-height: 1.2;
}

.editor p {
  margin: 8px 0 0;
  color: var(--muted);
  line-height: 1.6;
}

.icon-button {
  width: 42px;
  min-width: 42px;
  padding: 0;
  font-size: 22px;
  line-height: 1;
}

.subtle {
  color: #4d5864;
  background: #f8fafc;
}

fieldset {
  margin: 18px 0 0;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
}

legend {
  padding: 0 6px;
  color: #3a4450;
  font-size: 13px;
  font-weight: 800;
}

.section-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

label {
  display: grid;
  gap: 6px;
  min-width: 0;
  color: #3d4650;
  font-size: 12px;
  font-weight: 800;
}

input[type="text"],
input[type="number"],
select {
  width: 100%;
  height: 38px;
  border: 1px solid #b7bfc8;
  border-radius: 6px;
  padding: 0 10px;
  background: #ffffff;
  color: #101820;
}

input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid #b7bfc8;
  border-radius: 6px;
  padding: 4px 6px;
  background: #ffffff;
}

input[type="range"] {
  width: 100%;
}

.library-panel {
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.help-panel {
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.help-list {
  margin: 14px 0 0;
  padding-left: 24px;
  line-height: 1.8;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(15, 23, 42, 0.42);
}

.modal-backdrop[hidden] {
  display: none;
}

.modal-panel {
  width: min(720px, 100%);
  max-height: min(720px, calc(100vh - 36px));
  overflow: auto;
  box-shadow: var(--shadow);
}

.library-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.library-head h2 {
  margin: 0;
  font-size: 16px;
}

.library-head p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.library-form {
  display: grid;
  grid-template-columns: 1fr 112px 130px 120px;
  gap: 8px;
}

.file-button {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 38px;
  border: 1px solid #aab2bc;
  border-radius: 8px;
  background: #f8fafc;
  color: #18202a;
  font-size: 13px;
  font-weight: 800;
  overflow: hidden;
}

.file-button input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.library-list {
  display: grid;
  gap: 6px;
  margin-top: 10px;
  max-height: 420px;
  overflow: auto;
}

.library-item {
  display: grid;
  grid-template-columns: 42px 1fr auto;
  gap: 8px;
  align-items: center;
  padding: 6px;
  border: 1px solid #e0e4e8;
  border-radius: 8px;
  background: #fbfcfd;
}

.library-item img {
  width: 42px;
  height: 42px;
  object-fit: contain;
  background: #fff;
}

.library-meta {
  min-width: 0;
}

.library-meta strong,
.library-meta span {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.library-meta span {
  color: var(--muted);
  font-size: 11px;
}

.library-category-select {
  width: 120px;
  min-height: 30px;
  margin-top: 5px;
  padding: 4px 8px;
  font-size: 12px;
}

.empty-library {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
}

.bulk-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.players {
  display: grid;
  gap: 12px;
  margin-top: 16px;
}

.player-card {
  border: 1px solid #d5dae0;
  border-radius: 8px;
  padding: 12px;
  background: #fbfcfd;
}

.player-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 10px;
  border-radius: 6px;
  cursor: pointer;
  outline: none;
}

.player-head:focus-visible {
  box-shadow: 0 0 0 3px rgba(23, 110, 229, 0.22);
}

.player-head:hover .player-title {
  color: #0f6c35;
}

.player-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  color: #111;
  font-weight: 900;
  min-width: 0;
}

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

.toggle-button {
  min-width: 64px;
}

.player-card.collapsed {
  padding-bottom: 10px;
}

.player-card.collapsed .player-head {
  margin-bottom: 0;
}

.row-number {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: #121820;
  color: #fff;
  font-size: 14px;
}

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

.player-grid[hidden] {
  display: none;
}

.hero-row {
  display: grid;
  grid-template-columns: minmax(240px, 1.25fr) minmax(120px, 0.75fr);
  gap: 10px;
  align-items: end;
}

.image-drop {
  position: relative;
  display: grid;
  place-items: center;
  min-height: 74px;
  border: 1px dashed #9fa9b4;
  border-radius: 8px;
  background: #ffffff;
  color: #596573;
  text-align: center;
  overflow: hidden;
}

.image-drop.hero {
  aspect-ratio: 1;
}

.image-drop.hero.horizontal {
  width: 86px;
  min-height: 86px;
}

.image-drop.board {
  grid-column: 1 / -1;
  aspect-ratio: 2976 / 660;
}

.image-drop.small-slot {
  min-height: 78px;
  aspect-ratio: 0.72;
}

.image-drop input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.image-drop img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.image-drop.board img {
  object-fit: contain;
  background: #fff;
}

.drop-label {
  padding: 8px;
  font-size: 12px;
  line-height: 1.45;
}

.fields {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.slot-grid {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}

.asset-picker {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.asset-picker.hero-picker {
  grid-template-columns: 86px minmax(0, 1fr);
  align-items: end;
}

.asset-picker .image-drop {
  min-height: 76px;
}

.asset-controls {
  display: grid;
  gap: 6px;
}

.asset-controls input,
.asset-controls select {
  height: 32px;
  padding: 0 8px;
  font-size: 12px;
}

.asset-controls .file-button {
  min-height: 32px;
  font-size: 12px;
}

.board-options {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.fine-tune {
  grid-column: 1 / -1;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-items: end;
}

.number-control {
  display: grid;
  gap: 6px;
  font-size: 11px;
}

.number-control input[type="number"] {
  height: 34px;
  padding: 0 8px;
  text-align: right;
}

.fine-tune label {
  font-size: 11px;
}

.fine-tune input[type="range"] {
  width: 100%;
}

.range-field {
  display: grid;
  gap: 6px;
}

.range-head {
  display: grid;
  grid-template-columns: 1fr 70px;
  gap: 8px;
  align-items: center;
}

.range-head input[type="number"] {
  height: 30px;
  padding: 0 6px;
  text-align: right;
  font-size: 12px;
}

.preview-pane {
  position: sticky;
  top: 18px;
  padding: 14px;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

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

.save-button {
  position: relative;
  min-width: 132px;
  padding: 0 18px 0 42px;
}

.save-button::before {
  content: "↓";
  position: absolute;
  left: 15px;
  top: 50%;
  display: grid;
  place-items: center;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  transform: translateY(-50%);
  font-weight: 900;
}

.preview-toolbar div {
  display: grid;
  gap: 2px;
}

.preview-toolbar span {
  color: var(--muted);
  font-size: 13px;
}

.canvas-wrap {
  overflow: auto;
  border: 1px solid #cbd1d8;
  background:
    linear-gradient(45deg, #d8dde3 25%, transparent 25%),
    linear-gradient(-45deg, #d8dde3 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #d8dde3 75%),
    linear-gradient(-45deg, transparent 75%, #d8dde3 75%);
  background-position:
    0 0,
    0 10px,
    10px -10px,
    -10px 0;
  background-size: 20px 20px;
}

canvas {
  display: block;
  width: min(100%, 1180px);
  height: auto;
  background: #ffffff;
}

@media (max-width: 1100px) {
  .workspace {
    grid-template-columns: 1fr;
  }

  .editor {
    max-height: none;
  }

  .preview-pane {
    position: static;
  }
}

@media (max-width: 620px) {
  .app-shell {
    padding: 10px;
  }

  .section-grid,
  .bulk-actions,
  .fields,
  .fine-tune,
  .library-form,
  .board-options {
    grid-template-columns: 1fr;
  }

  .hero-row {
    grid-template-columns: 1fr;
  }

  .asset-picker.hero-picker {
    grid-template-columns: 86px minmax(0, 1fr);
  }

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