:root {
  color-scheme: light;
  font-family: "Microsoft YaHei UI", "Noto Sans CJK SC", "PingFang SC", sans-serif;
  color: #20304b;
  background: #f3f9ff;
  --ink: #20304b;
  --muted: #60738b;
  --teal: #087f88;
  --line: #dce8f2;
}

* {
  box-sizing: border-box;
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  background:
    radial-gradient(circle at 10% 6%, rgba(255, 229, 154, 0.32), transparent 23rem),
    radial-gradient(circle at 92% 14%, rgba(166, 235, 231, 0.3), transparent 25rem),
    #f3f9ff;
}

button,
input,
select {
  font: inherit;
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
a:focus-visible {
  outline: 3px solid #173a63;
  outline-offset: 3px;
}

.admin-shell {
  width: min(calc(100% - 32px), 1180px);
  margin: 0 auto;
  padding: 28px 0 42px;
}

.admin-header {
  display: flex;
  align-items: flex-start;
  gap: 24px;
  margin-bottom: 22px;
}

.back-link {
  display: inline-flex;
  min-height: 42px;
  align-items: center;
  padding: 0 12px;
  border: 1px solid #cddce8;
  border-radius: 13px;
  background: #fff;
  color: #31546d;
  font-size: 0.9rem;
  font-weight: 800;
  text-decoration: none;
  white-space: nowrap;
}

.admin-eyebrow {
  margin: 0 0 4px;
  color: #087b80;
  font-size: 0.86rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.7rem, 4vw, 2.35rem);
  line-height: 1.15;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  padding: 6px;
  border: 1px solid #dbe6ef;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.72);
}

.admin-tab {
  min-height: 42px;
  flex: 1;
  padding: 0 12px;
  border: 0;
  border-radius: 11px;
  background: transparent;
  color: #566a82;
  cursor: pointer;
  font-weight: 800;
}

.admin-tab.is-active {
  background: #087f88;
  color: #fff;
  box-shadow: 0 3px 8px rgba(8, 127, 136, 0.22);
}

.admin-panel-wrap {
  min-height: 55vh;
  padding: clamp(16px, 3vw, 28px);
  border: 1px solid rgba(213, 228, 240, 0.9);
  border-radius: 24px;
  background: rgba(255, 255, 255, 0.96);
  box-shadow: 0 16px 42px rgba(50, 81, 116, 0.1);
}

.admin-panel {
  display: none;
}

.admin-panel.is-active {
  display: block;
}

.panel-heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.panel-heading h2 {
  margin-bottom: 5px;
  font-size: 1.45rem;
}

.panel-heading p,
.field-hint {
  margin-bottom: 0;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.upload-form {
  display: grid;
  grid-template-columns: minmax(180px, 0.8fr) minmax(240px, 1.2fr) auto;
  align-items: end;
  gap: 12px;
  padding: 16px;
  border: 1px solid #dce8f2;
  border-radius: 17px;
  background: #f8fbfe;
}

.crop-dialog {
  width: min(94vw, 720px);
  max-height: 92dvh;
  overflow-y: auto;
  padding: 0;
  border: 2px solid #bad7e2;
  border-radius: 22px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(30, 57, 79, 0.3);
}

.crop-dialog::backdrop {
  background: rgba(25, 43, 62, 0.58);
}

.image-preview-dialog {
  width: min(94vw, 1000px);
  max-height: 92dvh;
  overflow: auto;
  padding: clamp(12px, 2vw, 20px);
  border: 2px solid #bad7e2;
  border-radius: 22px;
  background: #fff;
  color: var(--ink);
  box-shadow: 0 24px 70px rgba(30, 57, 79, 0.3);
}

.image-preview-dialog::backdrop {
  background: rgba(25, 43, 62, 0.58);
}

.image-preview-content {
  display: grid;
  gap: 12px;
}

.image-preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.image-preview-header h2 {
  overflow-wrap: anywhere;
  margin: 0;
  font-size: 1.15rem;
}

.image-preview-image {
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 78dvh;
  margin: 0 auto;
  border-radius: 12px;
  object-fit: contain;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #dbe4e9 25%, transparent 25%),
    linear-gradient(-45deg, #dbe4e9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dbe4e9 75%),
    linear-gradient(-45deg, transparent 75%, #dbe4e9 75%);
  background-position: 0 0, 0 10px, 10px -10px, -10px 0;
  background-size: 20px 20px;
}

.crop-dialog-content {
  padding: clamp(16px, 4vw, 24px);
}

.crop-dialog-header h2 {
  margin: 0 0 5px;
  font-size: 1.35rem;
}

.crop-dialog-header p {
  margin: 0 0 15px;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.5;
}

.crop-stage {
  width: 100%;
  height: min(54dvh, 480px);
  min-height: 220px;
  margin: 0 auto 16px;
  overflow: hidden;
  border: 2px solid #bdd5df;
  border-radius: 15px;
  background-color: #fff;
  background-image:
    linear-gradient(45deg, #dbe4e9 25%, transparent 25%),
    linear-gradient(-45deg, #dbe4e9 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #dbe4e9 75%),
    linear-gradient(-45deg, transparent 75%, #dbe4e9 75%);
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
  background-size: 24px 24px;
}

.crop-stage canvas {
  display: block;
  width: 100%;
  height: 100%;
  cursor: crosshair;
  touch-action: none;
}

.crop-stage canvas.is-dragging {
  cursor: crosshair;
}

.crop-selection-message {
  margin: -5px 0 14px;
  color: var(--muted);
  font-size: 0.88rem;
  font-weight: 700;
}

.crop-selection-message.is-error {
  color: #a33d2d;
}

.crop-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.cropped-card-preview {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 12px;
  color: #415773;
  font-size: 0.86rem;
  font-weight: 800;
}

.cropped-card-preview[hidden] {
  display: none;
}

.cropped-card-preview img {
  width: 54px;
  height: 54px;
  border: 1px solid #dce7f0;
  border-radius: 9px;
  background: #eff6fa;
  object-fit: contain;
}

.cropped-card-preview button {
  margin-left: auto;
}

.field-label {
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 7px;
  color: #415773;
  font-size: 0.86rem;
  font-weight: 800;
}

.field-label input,
.field-label select {
  width: 100%;
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid #cbd9e5;
  border-radius: 11px;
  background: #fff;
  color: #21354f;
  font-weight: 600;
}

.field-label input[type="file"] {
  padding: 6px;
  font-size: 0.82rem;
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  padding: 0 13px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  font-size: 0.88rem;
  font-weight: 800;
  white-space: nowrap;
}

.primary-button {
  background: #087f88;
  color: #fff;
}

.secondary-button {
  border-color: #cbd9e5;
  background: #fff;
  color: #37546f;
}

.danger-button {
  border-color: #f0c7b4;
  background: #fff6f1;
  color: #9b4c2c;
}

.form-message {
  min-height: 1.25em;
  margin: 9px 0 0;
  color: #176c49;
  font-size: 0.88rem;
  font-weight: 700;
}

.form-message.is-error {
  color: #a33d2d;
}

.asset-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.asset-card,
.sound-card,
.level-card,
.settings-card {
  border: 1px solid #dce7f0;
  border-radius: 17px;
  background: #fff;
  box-shadow: 0 5px 16px rgba(43, 72, 100, 0.06);
}

.asset-card {
  overflow: hidden;
  padding: 10px;
}

.asset-preview {
  display: grid;
  width: 100%;
  height: 150px;
  place-items: center;
  overflow: hidden;
  padding: 0;
  border: 0;
  border-radius: 12px;
  background: #eff6fa;
  color: inherit;
  cursor: zoom-in;
  font: inherit;
}

.asset-preview img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.asset-card .field-label {
  margin: 10px 0;
}

.asset-actions,
.form-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.settings-card {
  margin-top: 16px;
  padding: 17px;
}

.settings-card h3 {
  margin-bottom: 14px;
  font-size: 1.08rem;
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.settings-grid .field-label {
  margin: 0;
}

.sound-list {
  display: grid;
  gap: 10px;
  margin-top: 16px;
}

.sound-card {
  display: grid;
  grid-template-columns: minmax(160px, 0.8fr) minmax(220px, 1.2fr) auto;
  align-items: center;
  gap: 12px;
  padding: 12px;
}

.sound-card audio {
  width: 100%;
  height: 38px;
}

.sound-card .field-label {
  margin: 0;
}

.level-layout {
  display: grid;
  grid-template-columns: minmax(300px, 1fr) minmax(260px, 0.8fr);
  align-items: start;
  gap: 18px;
}

.level-form {
  margin: 0;
}

.level-form > .field-label {
  margin-bottom: 17px;
}

.card-selection-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 9px;
  color: #415773;
  font-size: 0.86rem;
  font-weight: 800;
}

.card-selection-heading strong {
  color: var(--teal);
  font-variant-numeric: tabular-nums;
}

.card-selection-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
}

.card-choice {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 8px;
  padding: 6px;
  border: 1px solid #dce7f0;
  border-radius: 11px;
  background: #fff;
  cursor: pointer;
  font-size: 0.83rem;
  font-weight: 700;
}

.card-choice:has(input:checked) {
  border-color: #40aab1;
  background: #effafa;
}

.card-choice input {
  flex: 0 0 auto;
  width: 17px;
  height: 17px;
  accent-color: #087f88;
}

.card-choice img {
  width: 36px;
  height: 36px;
  flex: 0 0 36px;
  border-radius: 7px;
  background: #f1f6f9;
  object-fit: contain;
}

.card-choice span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sound-section-title {
  margin: 19px 0 5px !important;
}

.level-sound-grid {
  grid-template-columns: 1fr;
  margin: 10px 0 14px;
}

.saved-levels-title {
  margin: 0 0 10px;
  font-size: 1.08rem;
}

.level-list {
  display: grid;
  gap: 10px;
}

.level-card {
  padding: 14px;
}

.level-card h4 {
  margin: 0 0 5px;
  font-size: 1rem;
}

.level-card p {
  margin: 0 0 11px;
  color: var(--muted);
  font-size: 0.84rem;
}

.empty-state {
  padding: 18px;
  border: 1px dashed #c8d8e5;
  border-radius: 14px;
  color: var(--muted);
  font-size: 0.9rem;
  text-align: center;
}

@media (max-width: 760px) {
  .upload-form,
  .sound-card {
    grid-template-columns: 1fr;
  }

  .level-layout {
    grid-template-columns: 1fr;
  }

  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 520px) {
  .admin-shell {
    width: calc(100% - 18px);
    padding-top: 14px;
  }

  .admin-header {
    gap: 12px;
    margin-bottom: 14px;
  }

  .back-link {
    min-height: 36px;
    padding: 0 8px;
    font-size: 0.78rem;
  }

  .admin-tabs {
    gap: 4px;
    padding: 4px;
  }

  .admin-tab {
    min-height: 38px;
    padding: 0 5px;
    font-size: 0.82rem;
  }

  .admin-panel-wrap {
    padding: 13px;
    border-radius: 18px;
  }

  .upload-form,
  .settings-card {
    padding: 12px;
  }

  .crop-dialog {
    width: calc(100% - 18px);
    border-radius: 18px;
  }

  .crop-stage {
    height: min(45dvh, 360px);
    min-height: 190px;
  }

  .crop-actions > button {
    flex: 1;
    padding: 0 8px;
    font-size: 0.78rem;
  }

  .cropped-card-preview {
    flex-wrap: wrap;
    font-size: 0.78rem;
  }

  .cropped-card-preview button {
    min-height: 36px;
  }

  .asset-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .asset-preview {
    height: 110px;
  }

  .asset-card .field-label input {
    padding: 7px;
  }

  .asset-actions .primary-button,
  .asset-actions .danger-button {
    flex: 1;
    padding: 0 7px;
    font-size: 0.76rem;
  }
}
