:root {
  --bg: #0f172a;
  --surface: #1f2937;
  --surface-2: #374151;
  --text: #f1f5f9;
  --text-muted: #94a3b8;
  --primary: #f97316;
  --primary-hover: #ea580c;
  --border: #475569;
  --accent: #f59e0b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Apple SD Gothic Neo", "Noto Sans KR", sans-serif;
  font-size: 16px;
  min-height: 100vh;
}

header {
  padding: env(safe-area-inset-top) 16px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

header h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.5px;
  color: var(--accent);
  padding-top: 12px;
}

main {
  padding: 16px;
  max-width: 720px;
  margin: 0 auto;
  padding-bottom: env(safe-area-inset-bottom);
}

.control-group {
  margin-bottom: 16px;
}

.group-label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

textarea {
  width: 100%;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 18px;
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  resize: vertical;
  min-height: 100px;
}

textarea:focus {
  outline: 2px solid var(--primary);
  outline-offset: -1px;
}

.segmented {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
}

.seg {
  flex: 1;
  padding: 12px;
  background: transparent;
  color: var(--text-muted);
  border: 0;
  border-radius: 6px;
  font-size: 16px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, color 0.15s;
}

.seg.active {
  background: var(--primary);
  color: #ffffff;
}

.special-buttons {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
}

.special {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 0;
  font-size: 22px;
  cursor: pointer;
}

.special:active {
  background: var(--surface-2);
}

@media (max-width: 380px) {
  .special-buttons { grid-template-columns: repeat(4, 1fr); }
  .special { font-size: 20px; }
}

.actions {
  display: flex;
  gap: 8px;
  margin-top: 8px;
  margin-bottom: 16px;
}

.primary, .secondary {
  flex: 1;
  padding: 14px;
  font-size: 17px;
  font-weight: 600;
  border-radius: 10px;
  border: 0;
  cursor: pointer;
}

.primary {
  background: var(--primary);
  color: #ffffff;
}

.primary:hover { background: var(--primary-hover); }
.primary:disabled { background: var(--surface-2); color: var(--text-muted); cursor: not-allowed; }

.secondary {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
}

.secondary:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.status {
  min-height: 22px;
  font-size: 14px;
  color: var(--text-muted);
  margin-bottom: 8px;
}

.status.error { color: #ef4444; }
.status.success { color: #10b981; }

.preview-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px;
  min-height: 80px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
}

#preview {
  max-width: 100%;
  height: auto;
  display: none;
  border-radius: 4px;
  cursor: zoom-in;
}

#preview.shown { display: block; }

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.95);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: auto;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  -webkit-overflow-scrolling: touch;
}

.lightbox[hidden] { display: none; }

#lightbox-img {
  max-width: none;
  max-height: none;
  display: block;
  cursor: zoom-out;
}

.lightbox-close {
  position: fixed;
  top: max(12px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.15);
  color: #ffffff;
  font-size: 28px;
  line-height: 44px;
  text-align: center;
  cursor: pointer;
  padding: 0;
  z-index: 1001;
}

.lightbox-close:active { background: rgba(255, 255, 255, 0.3); }
