﻿:root {
  --bg-a: #fff6d3;
  --bg-b: #ffd8b2;
  --bg-c: #bde9ff;
  --panel: #0b2545;
  --panel-soft: #123d6b;
  --ink: #09253f;
  --text-main: #f6fbff;
  --text-soft: #d8ecff;
  --accent: #ff7a1a;
  --accent-2: #00bcd4;
  --good: #1bbf72;
  --danger: #ea4f6f;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: "Fredoka", "Nunito", sans-serif;
  color: var(--ink);
  background: linear-gradient(140deg, var(--bg-a) 0%, var(--bg-b) 38%, var(--bg-c) 100%);
  padding: clamp(10px, 1.8vw, 24px);
  overflow-x: hidden;
}

.sf-orb {
  position: fixed;
  border-radius: 999px;
  filter: blur(2px);
  opacity: 0.45;
  z-index: 0;
  pointer-events: none;
}

.sf-orb-a {
  width: 300px;
  height: 300px;
  background: radial-gradient(circle at 30% 30%, #ffffff 0%, #ffb347 45%, transparent 72%);
  top: -90px;
  right: -60px;
}

.sf-orb-b {
  width: 260px;
  height: 260px;
  background: radial-gradient(circle at 45% 45%, #ffffff 0%, #4dc7ff 50%, transparent 75%);
  left: -90px;
  bottom: -90px;
}

.sf-app {
  position: relative;
  z-index: 1;
  max-width: min(96vw, 1380px);
  margin: 0 auto;
  border-radius: 28px;
  padding: clamp(14px, 2.4vw, 24px);
  background: linear-gradient(160deg, #08233f 0%, #0c3257 55%, #1f5f88 100%);
  box-shadow: 0 26px 65px rgba(4, 20, 36, 0.35);
  color: var(--text-main);
  animation: float-in 400ms ease;
}

.sf-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.sf-header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

.sf-brand {
  display: flex;
  align-items: center;
  gap: 14px;
}

.sf-logo {
  width: clamp(70px, 7vw, 94px);
  height: clamp(70px, 7vw, 94px);
  object-fit: contain;
  border-radius: 16px;
  background: rgba(0, 0, 0, 0.22);
  padding: 8px;
}

.sf-eyebrow {
  margin: 0;
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: #a8d7ff;
}

.sf-header h1 {
  margin: 2px 0 4px;
  font-size: clamp(24px, 4vw, 38px);
  line-height: 1.04;
}

.sf-subtitle {
  margin: 0;
  color: var(--text-soft);
  font-size: clamp(14px, 1.8vw, 18px);
}

.sf-ghost-btn {
  border: 0;
  border-radius: 14px;
  padding: 12px 16px;
  font: inherit;
  font-weight: 600;
  color: #072e4c;
  background: linear-gradient(135deg, #ffd166 0%, #ff9f43 100%);
  box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
  cursor: pointer;
  transition: transform 180ms ease, box-shadow 180ms ease;
}

.sf-ghost-btn-alt {
  background: linear-gradient(135deg, #9ee5ff 0%, #53c9ff 100%);
}

.sf-icon-btn {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.18);
  color: #e8f6ff;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}

.sf-icon-btn:hover,
.sf-icon-btn:focus-visible {
  background: rgba(255, 255, 255, 0.28);
}

.sf-ghost-btn:hover,
.sf-ghost-btn:focus-visible {
  transform: translateY(-2px);
  box-shadow: 0 14px 24px rgba(0, 0, 0, 0.25);
}

.sf-panel,
.sf-stage-panel {
  margin-top: 16px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.08));
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  padding: 14px;
}

.sf-app.sf-focus-mode .sf-panel {
  display: none;
}

.sf-app.sf-focus-mode .sf-stage-panel {
  margin-top: 12px;
}

.sf-app.sf-focus-mode #draw-canvas {
  max-height: 90vh;
}

.sf-panel-head {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 16px;
}

.sf-panel h2 {
  margin: 0;
  font-size: 20px;
}

.sf-panel p {
  margin: 0;
  color: var(--text-soft);
  font-size: 13px;
}

.sf-character-list {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
  gap: 10px;
}

.sf-character-btn {
  border: 0;
  border-radius: 16px;
  padding: 10px;
  font: inherit;
  color: #e9f8ff;
  background: rgba(0, 0, 0, 0.21);
  cursor: pointer;
  transition: transform 180ms ease, background 180ms ease;
  display: grid;
  justify-items: center;
  gap: 8px;
}

.sf-character-btn img {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 10px;
}

.sf-character-btn span {
  font-weight: 600;
}

.sf-character-btn.active {
  background: linear-gradient(140deg, #00bcd4 0%, #00dd9d 100%);
  color: #033240;
  transform: translateY(-2px);
}

.sf-character-btn:hover,
.sf-character-btn:focus-visible {
  transform: translateY(-2px);
}

.sf-gallery-list {
  margin-top: 12px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(88px, 1fr));
  gap: 10px;
  min-height: 80px;
}

.sf-thumb-btn {
  border: 2px solid transparent;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 4px;
  cursor: pointer;
  transition: transform 160ms ease, border-color 160ms ease;
}

.sf-thumb-btn img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 8px;
  display: block;
}

.sf-thumb-btn.active {
  border-color: #ffd166;
  transform: translateY(-2px);
}

.sf-empty {
  margin: 0;
  color: var(--text-soft);
  font-size: 14px;
}

.sf-stage-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.sf-stage-controls {
  display: flex;
  gap: 14px;
  align-items: center;
  flex-wrap: wrap;
}

.sf-toolset {
  display: flex;
  gap: 8px;
}

.sf-tool {
  border: 0;
  border-radius: 11px;
  padding: 10px 14px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: #07314f;
  background: #d3efff;
  transition: transform 140ms ease, background 140ms ease;
}

.sf-tool.active {
  background: #ffd166;
}

.sf-tool:hover,
.sf-tool:focus-visible {
  transform: translateY(-1px);
}

.sf-size-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-soft);
  min-width: 220px;
}

.sf-size-wrap input[type="range"] {
  accent-color: #ff7a1a;
}

.sf-size-wrap span {
  min-width: 44px;
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.sf-canvas-wrap {
  margin-top: 10px;
  width: 100%;
  border-radius: 16px;
  padding: 10px;
  background: linear-gradient(180deg, #f0fbff 0%, #d2f2ff 100%);
  border: 1px solid rgba(0, 0, 0, 0.12);
  overflow: auto;
  display: flex;
  justify-content: center;
}

#draw-canvas {
  width: 100%;
  height: auto;
  max-height: none;
  display: block;
  margin: 0 auto;
  border-radius: 12px;
  background: #ffffff;
  box-shadow: inset 0 2px 8px rgba(0, 0, 0, 0.08);
  touch-action: none;
  cursor: crosshair;
}

#draw-canvas.tool-fill {
  cursor: cell;
}

#draw-canvas.tool-eraser {
  cursor: grab;
}

.sf-toolbar {
  position: sticky;
  bottom: 10px;
  margin-top: 14px;
  padding: 10px;
  border-radius: 16px;
  background: rgba(3, 21, 36, 0.76);
  backdrop-filter: blur(4px);
  display: grid;
  grid-template-columns: 1fr auto repeat(4, auto);
  gap: 8px;
  align-items: center;
}

.sf-color-grid {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.sf-color-btn {
  width: 34px;
  height: 34px;
  border-radius: 10px;
  border: 2px solid rgba(255, 255, 255, 0.36);
  cursor: pointer;
}

.sf-color-btn.active {
  border-color: #ffffff;
  transform: translateY(-1px);
}

#color-picker {
  width: 44px;
  height: 34px;
  border: 0;
  border-radius: 10px;
  background: transparent;
  cursor: pointer;
}

.sf-action-btn {
  border: 0;
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  color: #03283d;
  background: #bde9ff;
}

.sf-action-btn:disabled {
  opacity: 0.45;
  cursor: default;
}

.sf-cta {
  color: #ffffff;
  background: linear-gradient(135deg, #16c26d 0%, #0ba85d 100%);
}

.sf-toast {
  position: fixed;
  left: 50%;
  bottom: 18px;
  transform: translate(-50%, 10px);
  background: rgba(5, 23, 39, 0.92);
  color: #ffffff;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms ease, transform 180ms ease;
  z-index: 22;
}

.sf-toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.sf-loading {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(4, 22, 37, 0.88);
  border-radius: 28px;
  z-index: 25;
}

.sf-loading[hidden] {
  display: none;
}

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

.sf-modal {
  position: fixed;
  inset: 0;
  z-index: 50;
  overflow-y: auto;
  padding: 12px;
}

.sf-modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
}

.sf-modal-dialog {
  position: relative;
  width: min(460px, calc(100vw - 24px));
  margin: max(12px, 3vh) auto;
  max-height: calc(100vh - 24px);
  overflow-y: auto;
  border-radius: 16px;
  padding: 18px;
  color: #09253f;
  background: linear-gradient(180deg, #f4fbff 0%, #d8efff 100%);
  box-shadow: 0 18px 48px rgba(0, 0, 0, 0.35);
  -webkit-overflow-scrolling: touch;
}

.sf-modal-close {
  position: absolute;
  top: 8px;
  right: 8px;
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 9px;
  background: #083257;
  color: #ffffff;
  cursor: pointer;
}

.sf-modal-dialog h3 {
  margin: 0 0 8px;
}

.sf-modal-text {
  margin: 0 0 10px;
  font-size: 14px;
}

.sf-field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.sf-field span {
  font-size: 13px;
  font-weight: 600;
}

.sf-field input,
.sf-field select {
  width: 100%;
  border: 1px solid rgba(9, 37, 63, 0.24);
  border-radius: 10px;
  padding: 9px 10px;
  font: inherit;
}

.sf-admin-actions {
  display: flex;
  gap: 8px;
}

.sf-divider {
  border: 0;
  border-top: 1px solid rgba(9, 37, 63, 0.2);
  margin: 14px 0;
}

.sf-admin-loaded {
  margin-top: 6px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(90px, 1fr));
  gap: 8px;
  max-height: 220px;
  overflow: auto;
  padding: 4px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.58);
}

.sf-admin-item {
  border: 1px solid rgba(9, 37, 63, 0.2);
  border-radius: 8px;
  padding: 4px;
  background: #ffffff;
}

.sf-admin-item img {
  width: 100%;
  aspect-ratio: 3 / 4;
  object-fit: cover;
  border-radius: 6px;
  display: block;
}

.sf-admin-item-name {
  display: block;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.2;
  color: #123a57;
  word-break: break-word;
}

.sf-admin-empty {
  margin: 0;
  font-size: 12px;
  color: #3a5f7b;
}

.sf-modal-status {
  min-height: 20px;
  margin: 12px 0 0;
  font-size: 13px;
  color: #174869;
}

.sf-spinner {
  width: 34px;
  height: 34px;
  border-radius: 999px;
  border: 3px solid rgba(255, 255, 255, 0.35);
  border-top-color: #ffd166;
  animation: spin 900ms linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes float-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@media (max-width: 900px) {
  .sf-toolbar {
    grid-template-columns: 1fr auto;
  }

  .sf-toolbar .sf-action-btn {
    min-height: 42px;
  }
}

@media (max-width: 680px) {
  body {
    padding: 8px;
  }

  .sf-app {
    border-radius: 18px;
    padding: 10px;
  }

  .sf-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .sf-header-actions {
    width: 100%;
  }

  .sf-header-actions .sf-ghost-btn {
    flex: 1;
  }

  .sf-icon-btn {
    width: 44px;
    min-width: 44px;
  }

  .sf-brand {
    align-items: flex-start;
  }

  .sf-logo {
    width: 64px;
    height: 64px;
  }

  .sf-panel-head {
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
  }

  .sf-character-list {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

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

  .sf-toolset {
    width: 100%;
  }

  .sf-tool {
    flex: 1;
    text-align: center;
  }

  .sf-size-wrap {
    width: 100%;
    min-width: 0;
  }

  .sf-size-wrap input[type="range"] {
    flex: 1;
  }

  .sf-stage-controls {
    width: 100%;
    gap: 8px;
  }

  .sf-toolbar {
    grid-template-columns: 1fr;
    gap: 10px;
    position: static;
    bottom: auto;
    margin-top: 10px;
  }

  .sf-color-grid {
    justify-content: center;
  }

  #color-picker,
  .sf-action-btn {
    width: 100%;
  }

  .sf-admin-actions {
    flex-direction: column;
  }
}
