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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: #333;
  background: #f1f5f9;
}

/* ===== Header ===== */
header {
  background: #1e293b;
  color: white;
  padding: 1.25rem 1rem;
}

.header-inner {
  max-width: 1200px;
  margin: 0 auto;
}

.back-link {
  display: inline-block;
  color: #94a3b8;
  text-decoration: none;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  min-height: 44px;
  line-height: 44px;
  padding: 0 0.25rem;
  transition: color 0.2s;
}

.back-link:hover {
  color: #e2e8f0;
}

header h1 {
  font-size: 1.3rem;
  font-weight: 700;
  line-height: 1.3;
}

.subtitle {
  font-size: 0.875rem;
  color: #94a3b8;
  margin-top: 0.25rem;
}

/* ===== Main ===== */
main {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1rem;
}

/* ===== Ad Units ===== */
.ad-unit {
  margin: 1.25rem 0;
}

/* ===== App Layout ===== */
.app-layout {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  margin-bottom: 1rem;
}

/* ===== Settings Panel ===== */
.settings-panel {
  background: white;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
}

.settings-group {
  margin-bottom: 1.1rem;
}

.settings-group:last-of-type {
  margin-bottom: 1.5rem;
}

.settings-panel label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.4rem;
}

.settings-panel select,
.settings-panel input[type="text"] {
  width: 100%;
  padding: 0.55rem 0.75rem;
  font-size: 0.95rem;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #f8fafc;
  color: #1e293b;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%2394a3b8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  cursor: pointer;
  transition: border-color 0.2s;
}

.settings-panel select:focus,
.settings-panel input[type="text"]:focus {
  outline: none;
  border-color: #6366f1;
}

.settings-panel input[type="text"] {
  background-image: none;
}

/* ===== Background Presets ===== */
.bg-presets {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 0.6rem;
  flex-wrap: wrap;
}

.preset-btn {
  width: 36px;
  height: 36px;
  border-radius: 8px;
  border: 2px solid transparent;
  cursor: pointer;
  transition: transform 0.15s, border-color 0.15s;
  flex-shrink: 0;
  min-width: 44px;
  min-height: 44px;
  width: 44px;
  height: 44px;
}

.preset-btn:hover {
  transform: scale(1.1);
}

.preset-btn.active {
  border-color: white;
  box-shadow: 0 0 0 2px #6366f1;
}

.custom-color-row {
  display: flex;
  align-items: center;
  gap: 0.6rem;
}

.inline-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0 !important;
}

input[type="color"] {
  width: 44px;
  height: 44px;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  cursor: pointer;
  padding: 2px;
  background: #f8fafc;
}

/* ===== Download Button ===== */
.download-btn {
  display: block;
  width: 100%;
  padding: 0.8rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  background: #6366f1;
  color: white;
  border: none;
  border-radius: 10px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  min-height: 44px;
  letter-spacing: 0.02em;
}

.download-btn:hover {
  background: #4f46e5;
}

.download-btn:active {
  transform: scale(0.98);
}

.download-btn:disabled {
  background: #a5b4fc;
  cursor: not-allowed;
}

/* ===== Preview Area ===== */
.preview-area {
  flex: 1;
}

.preview-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

.preview-outer {
  border-radius: 12px;
  overflow: hidden;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #e2e8f0;
  padding: 1rem;
}

/* ===== Code Card ===== */
.code-card {
  border-radius: 12px;
  overflow: hidden;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  min-width: 280px;
  max-width: 100%;
}

.window-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 10px 14px;
  background: #2d2d2d;
}

.dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  flex-shrink: 0;
}

.dot-red    { background: #ff5f57; }
.dot-yellow { background: #ffbd2e; }
.dot-green  { background: #28c840; }

.window-filename {
  margin-left: 8px;
  font-size: 0.75rem;
  color: #94a3b8;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
}

.code-pre {
  margin: 0 !important;
  border-radius: 0 !important;
  overflow-x: auto;
}

.code-pre code {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, "Noto Sans Mono CJK JP", monospace !important;
  display: block;
  tab-size: 2;
}

/* Highlight.js override */
.hljs {
  border-radius: 0 !important;
  margin: 0 !important;
}

/* ===== Input Section ===== */
.input-section {
  background: white;
  border-radius: 12px;
  padding: 1.25rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  margin-bottom: 1rem;
}

.input-section label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: #64748b;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 0.5rem;
}

#code-input {
  width: 100%;
  min-height: 180px;
  padding: 0.75rem 1rem;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  border: 1px solid #e2e8f0;
  border-radius: 8px;
  background: #0f172a;
  color: #e2e8f0;
  resize: vertical;
  tab-size: 2;
  transition: border-color 0.2s;
  -webkit-text-size-adjust: 100%;
}

#code-input:focus {
  outline: none;
  border-color: #6366f1;
}

#code-input::placeholder {
  color: #475569;
}

/* ===== Howto Section ===== */
.howto-section {
  background: white;
  border-radius: 12px;
  padding: 1.5rem;
  box-shadow: 0 1px 4px rgba(0,0,0,0.08);
  margin-bottom: 1rem;
}

.howto-section h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: #1e293b;
  margin-top: 1.5rem;
  margin-bottom: 0.6rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid #e2e8f0;
}

.howto-section h2:first-child {
  margin-top: 0;
}

.howto-section ol,
.howto-section ul {
  padding-left: 1.4rem;
  color: #475569;
  font-size: 0.95rem;
}

.howto-section li {
  margin-bottom: 0.4rem;
  line-height: 1.7;
}

.howto-section p {
  color: #475569;
  font-size: 0.95rem;
  line-height: 1.8;
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  color: #94a3b8;
}

footer a {
  color: #64748b;
  text-decoration: none;
}

footer a:hover {
  text-decoration: underline;
}

footer p + p {
  margin-top: 0.4rem;
}

/* ===== Desktop Layout ===== */
@media (min-width: 768px) {
  header h1 {
    font-size: 1.6rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .app-layout {
    flex-direction: row;
    align-items: flex-start;
    gap: 1.25rem;
  }

  .settings-panel {
    width: 240px;
    flex-shrink: 0;
    position: sticky;
    top: 1rem;
  }

  .preview-outer {
    min-height: 320px;
    padding: 1.5rem;
  }

  #code-input {
    min-height: 220px;
  }
}

@media (min-width: 1024px) {
  .settings-panel {
    width: 260px;
  }
}

/* ===== Input error state ===== */
#code-input.input-error {
  border-color: #ef4444;
  animation: shake 0.3s ease;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25%       { transform: translateX(-4px); }
  75%       { transform: translateX(4px); }
}

/* ===== Preview download button (mobile only) ===== */
.download-btn-preview {
  display: block;
  margin-top: 0.75rem;
}

@media (min-width: 768px) {
  .download-btn-preview {
    display: none;
  }
}

/* ===== Capture-safe overrides (html2canvas) ===== */
#code-card.capturing {
  box-shadow: none;
}
