:root {
  --bg-0: #f6f0e7;
  --bg-1: #e8d7c0;
  --ink: #1f2a37;
  --panel: #fffaf2;
  --accent: #de6e4b;
  --accent-soft: #f3c9b7;
  --ring-a: #2f4858;
  --ring-b: #f26430;
  --panel-w: 330px;
  --tab-w: 26px;
  /* iOS safe area insets - populated by env() and used throughout */
  --safe-area-top: env(safe-area-inset-top);
  --safe-area-bottom: env(safe-area-inset-bottom);
  --safe-area-left: env(safe-area-inset-left);
  --safe-area-right: env(safe-area-inset-right);
}

html {
  background: #1A2F42;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  min-height: var(--actual-vh, 100vh);
  font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
  color: var(--ink);
  background:
    radial-gradient(circle at 8% 10%, #fff7ed 0 8%, transparent 9%),
    radial-gradient(circle at 92% 90%, #f5dec9 0 10%, transparent 11%),
    linear-gradient(155deg, var(--bg-0), var(--bg-1));
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

@media (hover: none) and (pointer: coarse) {
  html,
  body,
  body * {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
  }
}

.layout {
  display: grid;
  grid-template-columns: 1fr;
  width: 100vw;
  height: 100dvh;
  height: var(--actual-vh, 100dvh);
  margin: 0;
  padding: 0;
}

.panel {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--panel-w);
  height: 100dvh;
  height: var(--actual-vh, 100dvh);
  overflow: visible;
  z-index: 20;
  transition: transform 0.26s ease;
}

.layout.panel-hidden .panel {
  transform: translateX(calc(-1 * var(--panel-w)));
}

.panel-inner {
  width: 100%;
  height: 100%;
  overflow-y: auto;
  background: rgba(26, 47, 66, 0.95);
  backdrop-filter: blur(5px);
  border-right: 2px solid rgba(255, 255, 255, 0.18);
  /* Safe area padding: ensures content clears notch/home bar on iPhone */
  padding: 20px;
  padding-top: max(20px, calc(var(--safe-area-top, 0px) + 10px));
  padding-bottom: max(20px, calc(var(--safe-area-bottom, 0px) + 10px));
  display: flex;
  flex-direction: column;
  gap: 4px;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

.panel-inner::-webkit-scrollbar {
  display: none;
}

.panel-tab {
  position: absolute;
  top: 50%;
  right: calc(-1 * var(--tab-w));
  transform: translateY(-50%);
  width: var(--tab-w);
  height: 88px;
  background: rgba(26, 47, 66, 0.95);
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-left: none;
  border-radius: 0 10px 10px 0;
  cursor: pointer;
  padding: 0;
  box-shadow: 3px 0 8px rgba(0, 0, 0, 0.35);
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-size: 0;
  color: transparent;
}

.panel-tab::after {
  content: '';
  display: block;
  width: 10px;
  height: 10px;
  border-top: 2px solid rgba(232, 244, 253, 0.68);
  border-right: 2px solid rgba(232, 244, 253, 0.68);
  transform: rotate(45deg);
  margin: auto;
  transition: transform 0.26s ease;
}

.layout:not(.panel-hidden) .panel-tab::after {
  transform: rotate(225deg);
}

.panel-tab:hover {
  background: rgba(26, 47, 66, 0.95);
  border-color: rgba(255, 255, 255, 0.18);
}

.panel-logo {
  width: 100%;
  height: auto;
  margin-bottom: 0;
  -webkit-user-drag: none;
  pointer-events: none;
}

.subtitle {
  margin-top: -2px;
  margin-bottom: 1rem;
  font-size: 0.84rem;
  color: #ffffff;
  text-align: center;
}

label {
  display: grid;
  gap: 0.35rem;
  margin-bottom: 0.8rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #ffffff;
}

input,
select,
button {
  font: inherit;
}

select {
  width: 100%;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  background: #3A4F6A;
  color: #E8F4FD;
  padding: 10px 12px;
  appearance: none;
}

.radio-group {
  border: 1px solid #ffffff;
  border-radius: 8px;
  padding: 12px;
  padding-top: 8px;
  margin: 0 0 0.8rem 0;
}

.radio-group legend {
  display: block;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #ffffff;
  margin: -8px 0 0.5rem -12px;
  padding: 0 8px;
  width: auto;
}

.radio-options {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.radio-options label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0;
  padding-left: 16px;
  font-size: 0.75rem;
  text-transform: none;
  letter-spacing: normal;
  cursor: pointer;
}

input[type="radio"] {
  cursor: pointer;
  accent-color: #4A90E2;
  width: 16px;
  height: 16px;
  flex-shrink: 0;
}

input[type="color"] {
  width: 100%;
  height: 40px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 8px;
  padding: 2px;
  cursor: pointer;
  background: none;
}

.colour-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  margin-bottom: 0.8rem;
}

.colour-row label {
  margin-bottom: 0;
}

input[type="range"] {
  accent-color: #4A90E2;
}

.actions {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 0.5rem;
  align-items: stretch;
}

.share-link-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  letter-spacing: 0.04em;
  font-size: 10px;
  font-weight: 700;
}

.share-link-btn svg {
  flex: 0 0 auto;
}

button {
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 4px;
  background: #2A3F5A;
  color: #E8F4FD;
  font-size: 12px;
  line-height: 1.2;
  min-height: 40px;
  padding: 8px;
  text-align: center;
  text-transform: uppercase;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  box-sizing: border-box;
  transition: background 0.2s ease;
}

button.is-off {
  background: #556270;
  color: rgba(232, 244, 253, 0.72);
  border-color: rgba(255, 255, 255, 0.12);
}

@media (hover: hover) {
  button:hover {
    background: #354d6b;
  }

  button.is-off:hover {
    background: #5f6b78;
  }
}

.gear-note {
  margin: 0.2rem 0 0.6rem;
  font-size: 0.78rem;
  color: rgba(232, 244, 253, 0.68);
}

.stage-wrap {
  min-height: 0;
  height: 100%;
  border-radius: 0;
  background: linear-gradient(185deg, #fff6ea, #fde9d4);
  border: 0;
  box-shadow: none;
  overflow: hidden;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.help-close-btn {
  width: 20px;
  height: 20px;
  min-height: 20px;
  padding: 0;
  border: 1px solid #555;
  border-radius: 5px;
  background: #2A3F5A;
  color: #E8F4FD;
  font-size: 12px;
  line-height: 1;
  cursor: pointer;
  flex-shrink: 0;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  text-transform: none;
}

@media (hover: hover) {
  .help-close-btn:hover {
    filter: brightness(1.15);
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3);
  }
}

.help-close-btn:active {
  background: #E74C3C;
}

.help-overlay {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(5, 12, 18, 0.7);
  z-index: 2500;
  padding: 20px;
}

.help-overlay.show {
  display: flex;
}

.help-content {
  width: min(520px, 100%);
  max-height: min(88vh, calc(var(--actual-vh, 100vh) - 40px));
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 18px;
  background: rgba(26, 47, 66, 0.96);
  padding: 22px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.35);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.help-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
  flex-shrink: 0;
}

.help-header h2 {
  margin: 0;
  font-size: 1.02rem;
  color: #E8F4FD;
  letter-spacing: 0.02em;
}

.help-body {
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  scrollbar-width: thin;
}

.help-body::-webkit-scrollbar {
  width: 4px;
}

.help-body::-webkit-scrollbar-track {
  background: transparent;
}

.help-body::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.18);
  border-radius: 2px;
}

@media (max-width: 768px) {
  .help-body::-webkit-scrollbar {
    display: none;
  }

  .help-body {
    scrollbar-width: none;
  }
}

.help-section {
  display: flex;
  flex-direction: column;
  gap: 10px;
  color: #E8F4FD;
  line-height: 1.5;
}

.help-section p {
  margin: 0;
}

.help-section h3 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  color: #E8F4FD;
}

.help-section + .help-section {
  border-top: 1px solid rgba(255, 255, 255, 0.18);
  margin-top: 14px;
  padding-top: 14px;
}

.help-section a {
  color: #FFD700;
  text-decoration: underline;
  cursor: pointer;
  font-weight: 600;
}

.help-section a:hover {
  color: #FFED4E;
}

@media (max-width: 980px) {
  .panel {
    width: min(82vw, var(--panel-w));
  }

  .stage-wrap {
    min-height: 0;
    height: 100dvh;
    border-radius: 0;
  }
}
