﻿* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

html, body {
  height: 100%;
}

body {
  background: #050509;
  color: #f5f5f5;
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
}

header {
  padding: 10px 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  background: #11131a;
  border-bottom: 1px solid #262938;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  z-index: 10;
  flex-shrink: 0;
}

.header-top {
  display: flex;
  align-items: center;
  gap: 10px;
  width: auto;
  margin-right: 8px;
}

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

header h1 {
  font-size: 16px;
  white-space: nowrap;
}

#fullscreenBtn {
  min-height: 36px;
  padding: 6px 12px;
}

#controlsToggle {
  display: none;
  min-height: 36px;
  padding: 6px 12px;
}

.preset-group {
  gap: 6px;
}

.preset-btn.is-active {
  border-color: #ff4b9a;
  background: #2a1830;
  color: #ffd1f0;
}

.perf-banner {
  position: absolute;
  top: 12px;
  left: 12px;
  right: 12px;
  z-index: 8;
  max-width: 420px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid #3a4158;
  background: rgba(17, 19, 26, 0.94);
  box-shadow: 0 12px 28px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(8px);
}

.perf-banner[hidden] {
  display: none !important;
}

.perf-banner p {
  margin: 0 0 10px;
  font-size: 13px;
  line-height: 1.4;
  color: #e7e9f4;
}

.perf-banner-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.perf-banner-actions button {
  min-height: 34px;
}

#perfLowerBtn {
  border-color: #ff4b9a;
  background: #2a1830;
  color: #ffd1f0;
}

label {
  font-size: 12px;
  opacity: 0.9;
  margin-right: 4px;
}

select, input[type="text"], input[type="file"], button, input[type="color"] {
  font-size: 12px;
  padding: 4px 6px;
  border-radius: 4px;
  border: 1px solid #33384a;
  background: #181b26;
  color: #f5f5f5;
}

input[type="color"] {
  padding: 0;
  width: 32px;
  height: 22px;
  border-radius: 4px;
  cursor: pointer;
}

input[type="range"] {
  max-width: 120px;
  accent-color: #ff4b9a;
}

button {
  cursor: pointer;
  min-height: 28px;
}

button:hover {
  background: #222636;
}

button:disabled {
  opacity: 0.55;
  cursor: wait;
}

button:focus-visible,
select:focus-visible,
input:focus-visible,
a:focus-visible {
  outline: 2px solid #ff4b9a;
  outline-offset: 2px;
}

#controls-group {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  flex: 1;
}

#main {
  flex: 1;
  position: relative;
  min-height: 0;
}

#particleCanvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
  background: radial-gradient(circle at top, #1b1f33 0, #050509 55%);
}

#drawPanel {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 220px;
  height: 220px;
  max-width: calc(100% - 24px);
  background: #0b0d14;
  border: 1px solid #33384a;
  border-radius: 8px;
  padding: 6px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  z-index: 5;
}

#drawPanel h2 {
  font-size: 12px;
  margin-bottom: 2px;
}

#drawCanvas {
  flex: 1;
  width: 100%;
  border-radius: 4px;
  background: #ffffff;
  cursor: crosshair;
  touch-action: none;
}

#drawPanel button {
  width: 100%;
  margin-top: 2px;
}

#uploadPreviewPanel {
  position: absolute;
  top: 12px;
  right: 12px;
  width: 250px;
  max-width: calc(100% - 24px);
  background: rgba(11, 13, 20, 0.92);
  border: 1px solid #33384a;
  border-radius: 8px;
  padding: 6px;
  display: none;
  flex-direction: column;
  gap: 4px;
  z-index: 6;
  box-shadow: 0 10px 24px rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(6px);
}

#uploadPreviewPanel h2 {
  font-size: 11px;
  margin: 0;
}

#uploadPreviewImg {
  width: 100%;
  height: 180px;
  object-fit: contain;
  background: #050509;
  border-radius: 4px;
  border: 1px solid rgba(255, 255, 255, 0.06);
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
}

#uploadPreviewToggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 11px;
  opacity: 0.9;
}

#hint {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: max(12px, env(safe-area-inset-bottom));
  font-size: 11px;
  color: #a0a4c0;
  opacity: 0.8;
  pointer-events: none;
  max-width: 420px;
  line-height: 1.35;
}

.inline-group {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}

.small-label {
  font-size: 11px;
  opacity: 0.8;
}

.desktop-only {
  display: inline;
}

.mobile-only {
  display: none;
}

.site-footer {
  flex-shrink: 0;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px 16px;
  padding: 8px 16px;
  padding-left: max(16px, env(safe-area-inset-left));
  padding-right: max(16px, env(safe-area-inset-right));
  padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: #0c0e14;
  border-top: 1px solid #262938;
  font-size: 12px;
}

.site-footer a {
  color: #d7dae8;
  text-decoration: none;
}

.site-footer a:hover {
  color: #ffd1f0;
  text-decoration: underline;
}

.footer-nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 14px;
}

.footer-nav a {
  color: #a0a4c0;
}

/* Legal pages */
body.legal-page {
  overflow: auto;
  height: auto;
  min-height: 100vh;
  min-height: 100dvh;
}

.legal-wrap {
  width: min(720px, calc(100% - 32px));
  margin: 0 auto;
  padding: 28px 0 48px;
  line-height: 1.55;
}

.legal-wrap h1 {
  font-size: 1.6rem;
  margin-bottom: 8px;
}

.legal-wrap h2 {
  font-size: 1.05rem;
  margin-top: 1.4rem;
  margin-bottom: 0.4rem;
}

.legal-wrap p,
.legal-wrap li {
  color: #c8cada;
  font-size: 0.95rem;
  margin-bottom: 0.7rem;
}

.legal-wrap ul {
  padding-left: 1.2rem;
  margin-bottom: 0.8rem;
}

.legal-top {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 12px 16px;
  background: #11131a;
  border-bottom: 1px solid #262938;
}

.legal-top a {
  color: #ffd1f0;
  text-decoration: none;
}

.legal-top a:hover {
  text-decoration: underline;
}

@media (max-width: 900px) {
  header {
    padding: 8px 12px;
    padding-left: max(12px, env(safe-area-inset-left));
    padding-right: max(12px, env(safe-area-inset-right));
    align-items: stretch;
    flex-direction: column;
    gap: 0;
  }

  .header-top {
    width: 100%;
    justify-content: space-between;
    margin-right: 0;
    min-height: 40px;
  }

  .header-actions {
    margin-left: 0;
  }

  #controlsToggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
  }

  .perf-banner {
    top: 10px;
    left: 10px;
    right: 10px;
    max-width: none;
  }

  .preset-group {
    justify-content: flex-start;
  }

  .preset-btn {
    flex: 1 1 auto;
  }

  #controls-group {
    display: none;
    width: 100%;
    max-height: min(42vh, 320px);
    overflow-y: auto;
    padding: 10px 0 4px;
    gap: 10px;
    -webkit-overflow-scrolling: touch;
  }

  header.controls-open #controls-group {
    display: flex;
  }

  .inline-group {
    width: 100%;
    justify-content: space-between;
    gap: 8px;
    padding: 2px 0;
  }

  select,
  input[type="text"],
  input[type="file"],
  button {
    font-size: 14px;
    min-height: 40px;
    padding: 8px 10px;
  }

  input[type="color"] {
    width: 44px;
    height: 36px;
  }

  input[type="range"] {
    flex: 1;
    max-width: none;
    min-height: 32px;
  }

  #textWrapper,
  #uploadWrapper {
    width: 100%;
  }

  #textInput,
  #uploadInput {
    flex: 1;
    min-width: 0;
  }

  #controls-group > button {
    flex: 1 1 calc(50% - 8px);
    min-width: 140px;
  }

  #drawPanel {
    top: auto;
    bottom: max(48px, calc(12px + env(safe-area-inset-bottom)));
    right: 12px;
    left: 12px;
    width: auto;
    height: min(240px, 42vh);
  }

  #uploadPreviewPanel {
    top: 10px;
    right: 10px;
    left: auto;
    width: min(180px, 46vw);
  }

  #uploadPreviewImg {
    height: 110px;
  }

  #hint {
    font-size: 10px;
    bottom: max(10px, env(safe-area-inset-bottom));
  }

  .site-footer {
    flex-direction: column;
    align-items: flex-start;
    padding: 10px 12px;
    padding-bottom: max(10px, env(safe-area-inset-bottom));
  }

  .desktop-only {
    display: none;
  }

  .mobile-only {
    display: inline;
  }
}

@media (max-width: 480px) {
  header h1 {
    font-size: 15px;
  }

  #uploadPreviewPanel {
    width: min(150px, 42vw);
  }

  #uploadPreviewImg {
    height: 90px;
  }
}
