:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --border: #e2e4e9;
  --text: #1f2430;
  --text-muted: #6b7280;
  --primary: #4f6df5;
  --primary-hover: #3d59db;
  --primary-tint: #eef1ff;
  --danger: #e5484d;
  --danger-tint: #fdecec;
  --hover-surface: #f0f1f5;
  --checker-a: #e9eaee;
  --checker-b: #ffffff;
  --badge-bg: #eeeeee;
  --imported-bg: #fff4e5;
  --imported-text: #b6690a;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(15, 23, 42, 0.08), 0 1px 2px rgba(15, 23, 42, 0.04);
  color-scheme: light;
}

/* OSがダーク設定で、かつユーザーが明示的にライトを選んでいない場合 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #14161b;
    --surface: #1c1f26;
    --border: #333844;
    --text: #e8eaf0;
    --text-muted: #9aa1b0;
    --primary: #7c93ff;
    --primary-hover: #93a6ff;
    --primary-tint: #26304d;
    --danger: #ff6b6b;
    --danger-tint: #3d1f22;
    --hover-surface: #262a33;
    --checker-a: #2a2e37;
    --checker-b: #1c1f26;
    --badge-bg: #2a2e37;
    --imported-bg: #3a2f1a;
    --imported-text: #e0a94d;
    --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
  }
}

/* ユーザーが明示的にダークを選んだ場合(OS設定に関わらず) */
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #14161b;
  --surface: #1c1f26;
  --border: #333844;
  --text: #e8eaf0;
  --text-muted: #9aa1b0;
  --primary: #7c93ff;
  --primary-hover: #93a6ff;
  --primary-tint: #26304d;
  --danger: #ff6b6b;
  --danger-tint: #3d1f22;
  --hover-surface: #262a33;
  --checker-a: #2a2e37;
  --checker-b: #1c1f26;
  --badge-bg: #2a2e37;
  --imported-bg: #3a2f1a;
  --imported-text: #e0a94d;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.5), 0 1px 2px rgba(0, 0, 0, 0.4);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Kaku Gothic ProN",
    "Yu Gothic", sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}
.app-header h1 {
  font-size: 18px;
  margin: 0;
}
.header-controls {
  display: flex;
  gap: 20px;
  flex-wrap: wrap;
}
.lang-switch {
  display: flex;
  gap: 8px;
  align-items: center;
  font-size: 14px;
  color: var(--text-muted);
}
.lang-switch select {
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}

.app-layout {
  max-width: 1240px;
  margin: 0 auto;
  padding: 24px;
  padding-bottom: 96px;
  display: flex;
  align-items: flex-start;
  gap: 24px;
}

.app-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.app-preview {
  flex-shrink: 0;
  width: 360px;
  position: sticky;
  top: 84px;
}

.preview-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}
.preview-panel h2 {
  align-self: flex-start;
  margin: 0;
  font-size: 15px;
  font-weight: 600;
}
.preview-canvas-wrap {
  position: relative;
  width: 100%;
}
.preview-canvas {
  display: block;
  width: 100%;
  height: 320px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: repeating-conic-gradient(
      var(--checker-a) 0% 25%,
      var(--checker-b) 0% 50%
    )
    50% / 12px 12px;
  cursor: grab;
  touch-action: none;
}
.preview-canvas:active {
  cursor: grabbing;
}
.preview-empty {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  padding: 16px;
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.preview-empty.hidden {
  display: none;
}
.preview-name {
  margin: 0;
  font-size: 14px;
  font-weight: 600;
  min-height: 1.2em;
}
.preview-hint {
  margin: 0;
  font-size: 12px;
  color: var(--text-muted);
}

@media (max-width: 900px) {
  .app-layout {
    flex-direction: column;
  }
  .app-preview {
    width: 100%;
    position: static;
  }
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}
.card h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 600;
}

.add-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.file-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 10px 16px;
  background: var(--primary);
  color: #fff;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}
.file-btn:hover {
  background: var(--primary-hover);
}
.file-btn--secondary {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--primary);
}
.file-btn--secondary:hover {
  background: var(--primary-tint);
}

dl {
  margin: 0;
}
dt label,
dd label {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 14px;
  cursor: pointer;
}
.options-sub {
  padding-left: 24px;
  display: flex;
  flex-direction: column;
  margin: 0;
}
.options-nested {
  margin: 4px 0 0;
}

.options-row {
  display: flex;
  gap: 20px;
  align-items: center;
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
  flex-wrap: wrap;
  font-size: 14px;
}
.options-row select {
  margin-left: 6px;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
}
.hint {
  color: var(--text-muted);
  font-size: 12px;
}
.options-disabled-hint {
  margin: 0 0 12px;
  padding: 8px 10px;
  background: var(--primary-tint);
  border-radius: 6px;
}
.options-disabled-hint.hidden {
  display: none;
}
#panel-options fieldset,
#panel-options input:disabled,
#panel-options select:disabled {
  opacity: 0.5;
}

button {
  font: inherit;
  cursor: pointer;
}

#btn_reprocess {
  margin-top: 16px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
}
#btn_reprocess:hover {
  background: var(--hover-surface);
}

.panel-list-header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.select-all {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
  margin-left: auto;
}
.count-badge {
  background: var(--primary-tint);
  color: var(--primary);
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.empty-hint {
  color: var(--text-muted);
  font-size: 14px;
}
.empty-hint.hidden {
  display: none;
}

.skin-list {
  list-style: none;
  margin: 12px 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
  max-height: 480px;
  overflow-y: auto;
}
.skin-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
}
.skin-row--pinned {
  border-color: var(--primary);
  background: var(--primary-tint);
}
.pin-hint {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--primary);
  font-weight: 600;
  margin: 0;
  cursor: pointer;
}
.pin-hint.hidden {
  display: none;
}
.skin-select-wrap {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  cursor: pointer;
  padding: 8px;
  margin: -8px;
}
.skin-select {
  flex-shrink: 0;
  cursor: pointer;
  width: 18px;
  height: 18px;
}
.select-all input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}
.skin-thumb {
  width: 48px;
  height: 48px;
  object-fit: contain;
  image-rendering: pixelated;
  background: repeating-conic-gradient(
      var(--checker-a) 0% 25%,
      var(--checker-b) 0% 50%
    )
    50% / 10px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
  cursor: zoom-in;
  flex-shrink: 0;
}
.skin-name {
  flex: 1;
  min-width: 0;
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
}
.skin-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--badge-bg);
  color: var(--text-muted);
  white-space: nowrap;
  flex-shrink: 0;
}
.skin-badge--imported {
  background: var(--imported-bg);
  color: var(--imported-text);
}
.skin-actions {
  display: flex;
  gap: 4px;
  flex-shrink: 0;
}
.btn-icon {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--surface);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  line-height: 1;
  padding: 0;
}
.btn-icon {
  color: var(--text);
}
.btn-icon:hover:not(:disabled) {
  background: var(--hover-surface);
}
.btn-icon:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}
.btn-icon--danger:hover:not(:disabled) {
  background: var(--danger-tint);
  border-color: var(--danger);
  color: var(--danger);
}
.btn-delete-selected,
.btn-apply-selected {
  width: auto;
  height: auto;
  min-height: 28px;
  padding: 5px 12px;
  font-size: 12px;
  white-space: nowrap;
  border-radius: 6px;
}
.btn-apply-selected {
  border: 1px solid var(--primary);
  background: var(--surface);
  color: var(--primary);
}
.btn-apply-selected:hover:not(:disabled) {
  background: var(--primary-tint);
}

.app-footer {
  position: sticky;
  bottom: 0;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 20px;
  flex-wrap: wrap;
}
.footer-option {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  color: var(--text-muted);
  cursor: pointer;
}
.footer-actions {
  display: flex;
  gap: 12px;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  border: none;
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
}
.btn-primary:hover {
  background: var(--primary-hover);
}
.btn-secondary {
  background: var(--surface);
  color: var(--primary);
  border: 1px solid var(--primary);
  padding: 12px 28px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
}
.btn-secondary:hover {
  background: var(--primary-tint);
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 84px;
  transform: translate(-50%, 20px);
  background: #1f2430;
  color: #fff;
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 200;
  max-width: 90vw;
  text-align: center;
}
.toast--visible {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* 補完(スムージング)を消すためには指定しなきゃいけないらしい */
canvas {
  image-rendering: pixelated;
}

@media (max-width: 600px) {
  .skin-row {
    flex-wrap: wrap;
  }
  .skin-name {
    order: 3;
    flex-basis: 100%;
  }
}
