@font-face {
  font-family: "Monocraft";
  src: url("fonts/Monocraft.ttf") format("truetype");
}

* {
  box-sizing: border-box;
  image-rendering: pixelated;
}

:root {
  --bg: #1f1f1f;
  --container-bg: #1f1f1f;
  --text: #ffffff;
  --border: #2e2e2e;
  --accent: #3c8527;
  --accent-hover: #52a535;
  --accent-light: #7fdc5c;
  --footer-text: #aaaaaa;
  --footer-border: #2e2e2e;
}

[data-theme="light"] {
  --bg: #f5f5f5;
  --container-bg: #ffffff;
  --text: #171615;
  --border: #dddddd;
  --accent: #3c8527;
  --accent-hover: #52a535;
  --accent-light: #7fdc5c;
  --footer-text: #666666;
  --footer-border: #dddddd;
}

html, body {
  height: 100%;
  margin: 0;
}

body {
  font-family: "Inter", system-ui, sans-serif;
  background-color: var(--bg);
  color: var(--text);
  display: flex;
  flex-direction: column;
  transition: background-color 0.3s ease, color 0.3s ease;
}

main {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 20px;
}

.container {
  background-color: var(--container-bg);
  border: 2px solid var(--border);
  padding: 28px 28px 20px 28px;
  width: 100%;
  max-width: 1080px;
  text-align: center;
}

h1 {
  font-family: "Monocraft", monospace;
  font-size: 22px;
  margin-bottom: 20px;
}

#drop-area {
  border: 2px dashed var(--accent);
  padding: 24px;
  background-color: rgba(60, 133, 39, 0.1);
  cursor: pointer;
  transition: background-color 0.2s ease;
}

#drop-area.highlight {
  background-color: rgba(60, 133, 39, 0.2);
}

#drop-area input { display: none; }

.file-msg {
  margin-top: 12px;
  color: var(--accent-light);
  font-size: 14px;
}

button {
  font-family: "Inter", system-ui, sans-serif;
  margin-top: 16px;
  width: 100%;
  padding: 12px;
  background-color: var(--accent);
  border: 2px solid var(--border);
  color: white;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background-color 0.2s ease;
}

button:hover { background-color: var(--accent-hover); }
button:disabled { background-color: #555; cursor: not-allowed; }

/* Футер */
footer {
  position: relative;
  background-color: var(--container-bg);
  border-top: 1px solid var(--footer-border);
  padding: 10px 20px;
  font-size: 13px;
  color: var(--footer-text);
  text-align: center;
}

footer a {
  color: var(--accent-light);
  text-decoration: none;
  transition: color 0.2s ease;
}

footer a:hover {
  color: #b0ff9f;
}

.theme-switcher {
  position: absolute;
  right: 7px;
  top: 54%;
  transform: translateY(-50%);
  z-index: 10;
}

.switch-btn {
  display: inline-block;
  width: 44px;
  height: 24px;
  background: var(--border);
  cursor: pointer;
  box-shadow: none;
  position: relative;
  overflow: hidden;
}

.switch-btn::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  background-color: #fff;
  transition: left 0.3s ease;
  background-image: url("icons/sun.webp");
  background-position: center;
  background-size: 18px 18px;
}

.switch-btn.switch-on::after {
  left: 23px;

  background-image: url("icons/moon.webp");
}

.theme-icon {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: 16px;
  height: 16px;
  opacity: 0;
  pointer-events: none;
  z-index: 2;
}

.theme-icon.sun {
  opacity: 1;
}

.switch-btn.switch-on .sun {
  opacity: 0;
}

.switch-btn.switch-on .moon {
  opacity: 1;
}

/* Адаптивность */
@media (max-width: 600px) {
  main { padding: 10px; }
  .container { padding: 18px 18px 20px 18px; }
  h1 { font-size: 18px; }
  .loader { width: 140px; height: 140px; }
  .grid { width: 100px; height: 100px; }
  footer { padding: 10px; }

  .theme-switcher {
    right: 10px;
  }
  .switch-btn {
    width: 40px;
    height: 22px;
    border-radius: 11px;
  }
  .switch-btn::after {
    width: 16px;
    height: 16px;
    border-radius: 8px;
  }
  .switch-btn.switch-on::after {
    left: 21px;
  }
  .theme-icon {
    width: 14px;
    height: 14px;
  }
}

.modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.85);
  justify-content: center;
  align-items: center;
  z-index: 999;
  transition: opacity 0.35s ease;
  opacity: 1;
}

.modal.fade-out { opacity: 0; }
.modal.is-active { display: flex; }

.loader {
  width: 160px;
  height: 160px;
  background: var(--container-bg);
  border: 2px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.grid {
  width: 120px;
  height: 120px;
  display: grid;
  grid-template-columns: repeat(16, 1fr);
  grid-template-rows: repeat(16, 1fr);
  background: var(--bg);
}

.cell { background: transparent; }
.cell.gray { background: #bcbcbc; }
.cell.green { background: #7DB554; }

/* ===========================
   Tabs
=========================== */
.tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 18px;
}

.tab-btn {
  width: 100%;
  margin-top: 0;
  padding: 10px 12px;
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
  font-weight: 600;
}

.tab-btn:hover {
  background: rgba(60, 133, 39, 0.10);
}

.tab-btn.tab-active {
  border-color: var(--accent);
  background: rgba(60, 133, 39, 0.18);
}

.tab-panel { display: none; }
.tab-panel.tab-panel-active { display: block; }

/* ===========================
   Skin Editor Layout
=========================== */
.skin-layout {
  display: grid;
  grid-template-columns: 240px 1fr; /* инструменты слева, сцена/панель справа */
  gap: 18px;
  align-items: flex-start;
  text-align: left;
}

.skin-group-title {
  font-family: "Monocraft", monospace;
  font-size: 14px;
  margin-bottom: 10px;
  opacity: 0.95;
}

.skin-divider {
  height: 1px;
  background: var(--border);
  margin: 12px 0;
}

.skin-tools, .skin-right {
  border: 2px solid var(--border);
  padding: 12px;
  background: rgba(0,0,0,0.06);
}

/* Кнопка заголовка 2D-редактора (аккордеон) */
.skin-2d-toggle {
  width: 100%;
  margin: 0 0 6px 0;
  padding: 6px 8px;
  background: transparent;
  border: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.skin-2d-arrow {
  font-size: 12px;
  opacity: 0.7;
}

/* Контейнер содержимого 2D-редактора по умолчанию скрыт */
.skin-2d-body {
  overflow: hidden;
  max-height: 0;
  opacity: 0;
  margin-top: 0;
  transition: max-height 0.2s ease, opacity 0.2s ease, margin-top 0.2s ease;
}

.skin-2d-body.is-open {
  max-height: 1000px; /* достаточно для всего контента */
  opacity: 1;
  margin-top: 6px;
}

.tool-btn {
  width: 100%;
  margin-top: 8px;
  padding: 10px 10px;
  background: transparent;
  border: 2px solid var(--border);
  color: var(--text);
  display: grid;
  grid-template-columns: 24px 1fr;
  gap: 10px;
  align-items: center;
  font-weight: 600;
}

.tool-btn:hover {
  background: rgba(60, 133, 39, 0.10);
}

.tool-btn.tool-active {
  border-color: var(--accent);
  background: rgba(60, 133, 39, 0.18);
}

.kbd {
  font-family: "Monocraft", monospace;
  font-size: 11px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,0.20);
  opacity: 0.95;
  white-space: nowrap;
}

.canvas-wrap {
  border: 2px solid var(--border);
  background: var(--bg);
  padding: 10px;
  position: relative;
}

#skin2d {
  width: 100%;
  height: auto;
  display: block;
  background: #111;
  image-rendering: pixelated;
}

.canvas-hint {
  position: absolute;
  right: 10px;
  top: 10px;
  font-family: "Monocraft", monospace;
  font-size: 12px;
  opacity: 0.8;
}

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

.action-btn {
  margin-top: 0;
  padding: 10px 12px;
  width: 100%;
  border: 2px solid var(--border);
  background: var(--accent);
  color: #fff;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.action-btn.action-secondary {
  grid-column: span 2;
  background: transparent;
  color: var(--text);
}

.action-btn.action-secondary:hover {
  background: rgba(60, 133, 39, 0.10);
}

.preview-box {
  border: 2px solid var(--border);
  background: var(--bg);
  height: 520px;
  max-height: 70vh;
  overflow: hidden;
}

/* Skin tab should grow naturally, но отображение
   контролируется общим классом .tab-panel */
#panel-skin {
  overflow: visible;      /* ВАЖНО: не режем */
  height: auto;
  min-height: 0;
}

#panel-skin,
#panel-skin * {
  min-height: 0; /* fixes flex overflow clipping */
}

/* If you have some main container limiting height - neutralize */
.tab-panel {
  height: auto;
  min-height: 0;
  overflow: visible;
}

/* Make skin editor layout responsive and tall */
.skin-editor-wrap {
  width: 100%;
  max-width: 100%;
  overflow: visible;
}

/* Make the 3D canvas big */
#skin3d {
  width: 100%;
  height: min(78vh, 820px); /* БОЛЬШОЙ редактор */
  min-height: 520px;
  display: block;
  max-width: 100%;
  border-radius: 16px;
}

/* Prevent canvas from being squished by flex/grid */
.skin-preview {
  width: 100%;
  flex: 1;
  min-width: 0;
}

/* If parent uses flex/grid, ensure it can grow */
.skin-layout {
  display: grid;
  grid-template-columns: 320px 1fr; /* tools + preview */
  gap: 16px;
  align-items: start;
}

#skin3d {
  width: 100%;
  height: 520px;
  display: block;
  max-width: 100%;
  border-radius: 14px;
}

#skin3d.paint-mode {
  cursor: crosshair;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.seg-btn {
  margin-top: 0;
  padding: 10px 10px;
  width: 100%;
  border: 2px solid var(--border);
  background: transparent;
  color: var(--text);
  font-weight: 700;
}

.seg-btn:hover {
  background: rgba(60, 133, 39, 0.10);
}

.seg-btn.seg-active {
  border-color: var(--accent);
  background: rgba(60, 133, 39, 0.18);
}

.color-row {
  display: grid;
  grid-template-columns: 1fr 46px;
  gap: 10px;
  align-items: center;
}

#color-input {
  width: 100%;
  height: 40px;
  border: 2px solid var(--border);
  background: transparent;
  padding: 0;
}

.color-chip {
  width: 46px;
  height: 40px;
  border: 2px solid var(--border);
  background: #3c8527;
}

.opacity-row {
  margin-top: 10px;
}

.opacity-controls {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 10px;
  align-items: center;
}

#opacity-input {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  height: 6px;
  border-radius: 999px;
  background: var(--border);
  outline: none;
}

#opacity-input::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--border);
  cursor: pointer;
}

#opacity-input::-moz-range-thumb {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--border);
  cursor: pointer;
}

.opacity-value {
  font-family: "Monocraft", monospace;
  font-size: 12px;
  opacity: 0.9;
}

.palette {
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 8px;
}

.pal-color {
  width: 100%;
  aspect-ratio: 1 / 1;
  border: 2px solid var(--border);
  cursor: pointer;
}

.pal-color:hover {
  outline: 2px solid var(--accent-light);
}

.skin-status {
  margin-top: 12px;
  font-size: 13px;
  color: var(--footer-text);
}

.skin-hotkeys {
  font-size: 13px;
  color: var(--footer-text);
}

.hotkey-line {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-top: 6px;
}

@media (max-width: 980px) {
  .skin-layout {
    grid-template-columns: 1fr;
  }
  .preview-box, #skin3d {
    height: 240px;
  }
}