*, *::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: #f5f6fa;
}

/* ===== Header ===== */
header {
  background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
  color: white;
  padding: 1rem 1rem 1.5rem;
  text-align: center;
}

.back-nav {
  text-align: left;
  margin-bottom: 0.75rem;
}

.back-link {
  color: rgba(255, 255, 255, 0.75);
  text-decoration: none;
  font-size: 0.875rem;
  display: inline-block;
  min-height: 44px;
  line-height: 44px;
  padding: 0 0.25rem;
  transition: color 0.2s;
}

.back-link:hover {
  color: white;
}

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

.subtitle {
  font-size: 0.85rem;
  opacity: 0.8;
  margin-top: 0.375rem;
}

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

/* ===== Card ===== */
.card {
  background: white;
  border-radius: 10px;
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

.card h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #1a1a2e;
  margin-bottom: 1rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid #e8eaf0;
}

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

/* ===== Sample Grid ===== */
.sample-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(80px, 1fr));
  gap: 0.75rem;
}

.sample-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.375rem;
  padding: 0.75rem 0.5rem;
  background: #f5f6fa;
  border: 2px solid transparent;
  border-radius: 8px;
  cursor: pointer;
  font-size: 0.75rem;
  color: #555;
  min-height: 80px;
  transition: border-color 0.2s, background 0.2s;
  touch-action: manipulation;
}

.sample-btn:hover,
.sample-btn:focus {
  border-color: #4a6cf7;
  background: #eef1ff;
  outline: none;
}

.sample-btn svg {
  width: 36px;
  height: 36px;
}

/* ===== Tabs ===== */
.input-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.tab-btn {
  flex: 1;
  padding: 0.6rem 0.75rem;
  background: #f0f1f5;
  border: 2px solid transparent;
  border-radius: 6px;
  font-size: 0.875rem;
  font-weight: 600;
  color: #666;
  cursor: pointer;
  min-height: 44px;
  transition: all 0.2s;
  touch-action: manipulation;
}

.tab-btn.active {
  background: white;
  border-color: #4a6cf7;
  color: #4a6cf7;
}

.tab-pane {
  display: none;
}

.tab-pane.active {
  display: block;
}

/* ===== Textarea ===== */
label {
  display: block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #444;
  margin-bottom: 0.375rem;
}

textarea {
  width: 100%;
  padding: 0.75rem;
  font-size: 0.875rem;
  font-family: "SFMono-Regular", "Consolas", "Menlo", monospace;
  border: 1px solid #d0d3de;
  border-radius: 6px;
  resize: vertical;
  color: #333;
  line-height: 1.5;
  transition: border-color 0.2s;
}

textarea:focus {
  outline: none;
  border-color: #4a6cf7;
  box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.12);
}

/* ===== File Upload ===== */
.file-label {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 2rem 1rem;
  border: 2px dashed #c0c4d0;
  border-radius: 8px;
  cursor: pointer;
  text-align: center;
  color: #666;
  font-size: 0.875rem;
  font-weight: 600;
  transition: border-color 0.2s, background 0.2s;
  min-height: 120px;
  justify-content: center;
}

.file-label:hover,
.file-label.drag-over {
  border-color: #4a6cf7;
  background: #eef1ff;
  color: #4a6cf7;
}

.file-icon {
  font-size: 2rem;
}

.file-label input[type="file"] {
  display: none;
}

/* ===== Buttons ===== */
.btn-primary {
  display: block;
  width: 100%;
  margin-top: 1rem;
  padding: 0 1rem;
  height: 56px;
  font-size: 1rem;
  font-weight: 700;
  background: #4a6cf7;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
  touch-action: manipulation;
}

.btn-primary:hover {
  background: #3558e8;
}

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

.btn-download {
  background: #1a9b5e;
  margin-top: 1.25rem;
}

.btn-download:hover {
  background: #158050;
}

/* ===== Error ===== */
.error-msg {
  color: #e53935;
  font-size: 0.85rem;
  margin-top: 0.5rem;
  min-height: 1.2em;
}

/* ===== Color List ===== */
.color-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.color-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem;
  background: #f8f9ff;
  border-radius: 8px;
  border: 1px solid #e8eaf0;
}

.color-swatch-old {
  width: 36px;
  height: 36px;
  border-radius: 6px;
  border: 1px solid rgba(0,0,0,0.1);
  flex-shrink: 0;
}

.color-arrow {
  font-size: 1rem;
  color: #aaa;
  flex-shrink: 0;
}

.color-picker-wrap {
  position: relative;
  flex-shrink: 0;
}

.color-picker-wrap input[type="color"] {
  width: 44px;
  height: 44px;
  padding: 2px;
  border: 2px solid #d0d3de;
  border-radius: 6px;
  cursor: pointer;
  background: white;
  transition: border-color 0.2s;
}

.color-picker-wrap input[type="color"]:hover,
.color-picker-wrap input[type="color"]:focus {
  border-color: #4a6cf7;
  outline: none;
}

.color-info {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  flex: 1;
  min-width: 0;
}

.color-hex {
  font-size: 0.8rem;
  font-family: "SFMono-Regular", "Consolas", monospace;
  color: #555;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.color-usage {
  font-size: 0.75rem;
  color: #888;
}

/* ===== Size Row ===== */
.size-row {
  display: flex;
  gap: 1rem;
  margin-top: 1.25rem;
}

.size-field {
  flex: 1;
}

.size-field label {
  margin-bottom: 0.25rem;
}

.size-field input[type="number"] {
  width: 100%;
  padding: 0.6rem 0.75rem;
  font-size: 1rem;
  border: 1px solid #d0d3de;
  border-radius: 6px;
  color: #333;
  transition: border-color 0.2s;
  min-height: 44px;
}

.size-field input[type="number"]:focus {
  outline: none;
  border-color: #4a6cf7;
  box-shadow: 0 0 0 3px rgba(74, 108, 247, 0.12);
}

/* ===== Preview ===== */
.preview-area {
  min-height: 160px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: repeating-conic-gradient(#e0e0e0 0% 25%, white 0% 50%) 0 0 / 20px 20px;
  border-radius: 8px;
  border: 1px solid #e0e2ea;
  padding: 1.5rem;
  overflow: auto;
}

.preview-area svg {
  max-width: 100%;
  height: auto;
}

/* ===== Howto ===== */
.howto-section h2 {
  margin-top: 1.25rem;
}

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

.howto-section ol {
  padding-left: 1.375rem;
  color: #555;
  font-size: 0.925rem;
}

.howto-section li {
  margin-bottom: 0.5rem;
}

.howto-section p {
  color: #555;
  font-size: 0.925rem;
  line-height: 1.7;
}

/* ===== Hidden ===== */
.hidden {
  display: none;
}

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

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

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

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

/* ===== Responsive ===== */
@media (min-width: 640px) {
  header {
    padding: 1.25rem 2rem 2rem;
  }

  header h1 {
    font-size: 1.6rem;
  }

  .subtitle {
    font-size: 0.925rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .card {
    padding: 1.75rem;
  }

  .sample-grid {
    grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
  }

  .sample-btn svg {
    width: 48px;
    height: 48px;
  }
}
