:root {
  --bg: #0f1115;
  --panel: #171a21;
  --panel-2: #1e222b;
  --fg: #e6e8ec;
  --muted: #8a93a6;
  --accent: #f5c26b;
  --accent-2: #7cc4ff;
  --border: #272b35;
  --green: #9ae6b4;
  --red: #fca5a5;
}

*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans",
    "Hiragino Kaku Gothic ProN", Meiryo, sans-serif;
  font-size: 15px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--fg);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* --- Header --- */
header {
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 24px 24px 0;
}

.title-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 4px;
}

h1 {
  font-size: 28px;
  font-weight: 700;
  color: var(--accent);
}

#subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 16px;
}

/* --- Tabs --- */
.tab-bar {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--border);
  margin-top: 8px;
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  padding: 8px 20px;
  transition: color 0.15s, border-color 0.15s;
}

.tab:hover { color: var(--fg); }

.tab.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* --- Main --- */
main {
  flex: 1;
  max-width: 680px;
  width: 100%;
  margin: 0 auto;
  padding: 24px;
}

/* --- Generator layout --- */
.gen-layout {
  display: flex;
  gap: 32px;
  align-items: flex-start;
}

.gen-controls {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-width: 0;
}

.gen-preview {
  flex-shrink: 0;
}

#qr-canvas {
  display: block;
  border-radius: 8px;
  image-rendering: pixelated;
  background: #fff;
  max-width: 256px;
  max-height: 256px;
}

/* --- Fields --- */
.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field.row {
  flex-direction: row;
  align-items: center;
  gap: 12px;
}

label {
  font-size: 13px;
  color: var(--muted);
  white-space: nowrap;
}

textarea {
  width: 100%;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--fg);
  font-size: 14px;
  font-family: inherit;
  padding: 10px 12px;
  resize: vertical;
  transition: border-color 0.15s;
}

textarea:focus {
  outline: none;
  border-color: var(--accent-2);
}

.input-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

select {
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--fg);
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
}

select:focus { outline: none; border-color: var(--accent-2); }

input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

input[type="color"] {
  width: 40px;
  height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: none;
  cursor: pointer;
  padding: 2px;
}

.color-row {
  flex-direction: row;
  gap: 24px;
}

.color-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Buttons --- */
button {
  border: none;
  border-radius: 8px;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 8px 18px;
  transition: opacity 0.15s, background 0.15s;
}

button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.primary {
  background: var(--accent);
  color: #0f1115;
}

.primary:not(:disabled):hover { opacity: 0.85; }

.primary.active {
  background: var(--red);
}

.secondary {
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: var(--fg);
}

.secondary:not(:disabled):hover { background: var(--border); }

/* --- Scanner layout --- */
.scan-layout {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
}

.video-wrap {
  width: 100%;
  max-width: 480px;
  aspect-ratio: 4/3;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

#scan-video {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.result-box {
  width: 100%;
  max-width: 480px;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.label {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.scan-result {
  font-size: 15px;
  word-break: break-all;
  min-height: 2.4em;
  transition: color 0.2s;
}

.scan-result.flash {
  color: var(--green);
  animation: flash 0.4s ease-out;
}

@keyframes flash {
  0% { background: rgba(154, 230, 180, 0.25); border-radius: 4px; }
  100% { background: transparent; }
}

.result-actions {
  display: flex;
  gap: 10px;
}

/* --- Utility --- */
.muted { color: var(--muted); font-size: 12px; }

.error {
  color: var(--red);
  font-size: 13px;
}

.group {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --- Footer --- */
footer {
  text-align: center;
  padding: 16px 24px 24px;
  color: var(--muted);
  font-size: 12px;
}

/* --- Responsive --- */
@media (max-width: 560px) {
  .gen-layout {
    flex-direction: column-reverse;
  }

  .gen-preview {
    width: 100%;
    display: flex;
    justify-content: center;
  }

  #qr-canvas {
    max-width: 200px;
    max-height: 200px;
  }

  .title-row {
    flex-wrap: wrap;
  }
}
