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

:root {
  --color-primary: #1a1f2e;
  --color-accent: #f05033;
  --color-accent-dark: #c0392b;
  --color-bg: #f0f2f5;
  --color-white: #ffffff;
  --color-border: #d8dce5;
  --color-text: #24292f;
  --color-text-muted: #6e7781;
  --color-hint: #57606a;
  --color-success: #1a7f37;
  --color-code-bg: #f6f8fa;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,0.1);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", "Segoe UI", sans-serif;
  font-size: 16px;
  line-height: 1.6;
  color: var(--color-text);
  background: var(--color-bg);
}

/* ===== Header ===== */
header {
  background: var(--color-primary);
  color: #fff;
  padding: 1rem;
}

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

.back-link {
  display: inline-block;
  color: rgba(255,255,255,0.7);
  text-decoration: none;
  font-size: 0.85rem;
  margin-bottom: 0.5rem;
  min-height: 44px;
  line-height: 44px;
  padding: 0 0.25rem;
  transition: color 0.15s;
}

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

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

.subtitle {
  font-size: 0.85rem;
  color: rgba(255,255,255,0.72);
  margin-top: 0.3rem;
}

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

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

/* ===== Tool Section ===== */
.tool-section {
  background: var(--color-white);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

/* ===== Form Group ===== */
.form-group {
  margin-bottom: 1.5rem;
}

.form-label {
  display: block;
  font-size: 0.9rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  color: var(--color-text);
}

.required {
  color: #cf222e;
  margin-left: 2px;
}

.optional {
  font-weight: 400;
  color: var(--color-text-muted);
  font-size: 0.82rem;
}

.field-hint {
  font-size: 0.8rem;
  color: var(--color-hint);
  margin-top: 0.35rem;
}

/* ===== Type Grid ===== */
.type-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 0.5rem;
}

.type-btn {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.65rem 0.75rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-white);
  cursor: pointer;
  text-align: left;
  min-height: 56px;
  transition: border-color 0.15s, background 0.15s, box-shadow 0.15s;
  width: 100%;
}

.type-btn:hover {
  border-color: var(--color-accent);
  background: #fff5f4;
}

.type-btn.selected {
  border-color: var(--color-accent);
  background: #fff0ee;
  box-shadow: 0 0 0 3px rgba(240,80,51,0.15);
}

.type-icon {
  font-size: 1.2rem;
  flex-shrink: 0;
  margin-top: 1px;
}

.type-info {
  display: flex;
  flex-direction: column;
}

.type-name {
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--color-text);
  line-height: 1.2;
}

.type-desc {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 2px;
  line-height: 1.3;
}

/* ===== Scope Input ===== */
.scope-wrapper {
  position: relative;
}

.scope-suggestions {
  position: absolute;
  top: calc(100% + 2px);
  left: 0;
  right: 0;
  background: var(--color-white);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12);
  z-index: 100;
  display: none;
  max-height: 200px;
  overflow-y: auto;
}

.scope-suggestions.visible {
  display: block;
}

.suggestion-item {
  padding: 0.6rem 0.75rem;
  cursor: pointer;
  font-size: 0.9rem;
  color: var(--color-text);
  min-height: 44px;
  display: flex;
  align-items: center;
  transition: background 0.1s;
}

.suggestion-item:hover,
.suggestion-item[aria-selected="true"] {
  background: var(--color-code-bg);
}

/* ===== Inputs ===== */
input[type="text"],
textarea {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  background: var(--color-white);
  transition: border-color 0.15s, box-shadow 0.15s;
  -webkit-appearance: none;
}

input[type="text"]:focus,
textarea:focus {
  outline: none;
  border-color: var(--color-accent);
  box-shadow: 0 0 0 3px rgba(240,80,51,0.15);
}

textarea {
  resize: vertical;
  min-height: 80px;
}

/* ===== Subject Counter ===== */
.subject-wrapper {
  position: relative;
}

.char-counter {
  position: absolute;
  bottom: 0.5rem;
  right: 0.6rem;
  font-size: 0.75rem;
  color: var(--color-text-muted);
  pointer-events: none;
}

.char-counter.warn {
  color: #d1242f;
  font-weight: 700;
}

/* ===== Breaking Change ===== */
.breaking-label {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  cursor: pointer;
  padding: 0.75rem 1rem;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-white);
  min-height: 56px;
  transition: border-color 0.15s, background 0.15s;
}

.breaking-label:has(input:checked) {
  border-color: #d1242f;
  background: #fff0f0;
}

.breaking-label input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin-top: 3px;
  flex-shrink: 0;
  accent-color: #d1242f;
  cursor: pointer;
}

.breaking-text {
  display: flex;
  flex-direction: column;
}

.breaking-text strong {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.95rem;
  color: #d1242f;
}

.breaking-text small {
  font-size: 0.8rem;
  color: var(--color-hint);
  margin-top: 2px;
}

.breaking-detail-wrap {
  display: none;
  margin-top: 0.75rem;
}

.breaking-detail-wrap.visible {
  display: block;
}

/* ===== Preview ===== */
.preview-section {
  background: var(--color-code-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-top: 1rem;
}

.preview-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.9rem;
  background: #e8ecf0;
  border-bottom: 1px solid var(--color-border);
}

.preview-label {
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.copy-btn {
  padding: 0.4rem 1rem;
  font-size: 0.85rem;
  font-weight: 700;
  background: var(--color-accent);
  color: #fff;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s, transform 0.1s;
}

.copy-btn:hover {
  background: var(--color-accent-dark);
}

.copy-btn:active {
  transform: scale(0.97);
}

.copy-btn.copied {
  background: var(--color-success);
}

.preview-code {
  padding: 1rem;
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
  font-size: 0.9rem;
  line-height: 1.6;
  color: var(--color-text);
  white-space: pre-wrap;
  word-break: break-word;
  min-height: 56px;
}

.preview-code.placeholder {
  color: var(--color-text-muted);
  font-style: italic;
}

.copy-feedback {
  font-size: 0.82rem;
  color: var(--color-success);
  padding: 0 0.9rem 0.5rem;
  min-height: 1.5rem;
}

/* ===== History ===== */
.history-section {
  background: var(--color-white);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
  margin-top: 1.5rem;
}

.history-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.history-header h2 {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text);
}

.clear-history-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  background: transparent;
  color: var(--color-text-muted);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.15s, color 0.15s;
}

.clear-history-btn:hover {
  background: #ffeef0;
  color: #d1242f;
  border-color: #ffa8a8;
}

.history-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.history-item {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.6rem 0.75rem;
  background: var(--color-code-bg);
  border: 1px solid var(--color-border);
  border-radius: 6px;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
}

.history-item:hover {
  border-color: var(--color-accent);
  background: #fff5f4;
}

.history-msg {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.82rem;
  color: var(--color-text);
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  flex: 1;
  min-width: 0;
}

.history-copy-icon {
  font-size: 0.9rem;
  flex-shrink: 0;
  margin-top: 2px;
  opacity: 0.55;
}

.history-empty {
  font-size: 0.88rem;
  color: var(--color-text-muted);
  text-align: center;
  padding: 1rem 0;
}

/* ===== HowTo Section ===== */
.howto-section {
  margin-top: 1.5rem;
  background: var(--color-white);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.howto-section h2 {
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 0.75rem;
  margin-top: 1.5rem;
  padding-bottom: 0.35rem;
  border-bottom: 2px solid var(--color-bg);
}

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

.howto-section ol {
  padding-left: 1.25rem;
}

.howto-section li {
  font-size: 0.9rem;
  color: #3d444b;
  margin-bottom: 0.6rem;
  line-height: 1.6;
}

.howto-section p {
  font-size: 0.9rem;
  color: #3d444b;
  line-height: 1.75;
}

.howto-section code {
  font-family: "SFMono-Regular", Consolas, monospace;
  font-size: 0.85em;
  background: var(--color-code-bg);
  border: 1px solid var(--color-border);
  border-radius: 4px;
  padding: 0.1em 0.35em;
  color: var(--color-accent-dark);
}

/* ===== Type Guide DL ===== */
.type-guide {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 0.5rem;
}

.type-guide-row {
  display: flex;
  align-items: baseline;
  gap: 0.75rem;
  padding: 0.45rem 0;
  border-bottom: 1px solid var(--color-bg);
  font-size: 0.88rem;
}

.type-guide-row:last-child {
  border-bottom: none;
}

.type-guide-row dt {
  flex-shrink: 0;
  width: 80px;
}

.type-guide-row dd {
  color: var(--color-hint);
}

/* ===== Footer ===== */
footer {
  text-align: center;
  padding: 2rem 1rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

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

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

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

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

  main {
    padding: 1.5rem 2rem;
  }

  .type-grid {
    grid-template-columns: repeat(3, 1fr);
  }

  .tool-section {
    padding: 1.75rem;
  }

  .history-section,
  .howto-section {
    padding: 1.75rem;
  }
}

@media (min-width: 900px) {
  .type-grid {
    grid-template-columns: repeat(5, 1fr);
  }
}
