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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", "Hiragino Kaku Gothic ProN", sans-serif;
  font-size: 16px;
  line-height: 1.7;
  color: #333;
  background: #f5f7fa;
}

/* ========== Header ========== */
.site-header {
  background: #1a5276;
  color: white;
  padding: 1rem;
}

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

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

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

.site-header h1 {
  font-size: 1.25rem;
  line-height: 1.35;
  margin-bottom: 0.3rem;
}

.subtitle {
  font-size: 0.875rem;
  opacity: 0.85;
}

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

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

/* ========== Tool Section ========== */
.tool-section {
  background: white;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

/* ========== Input Block ========== */
.input-block {
  margin-bottom: 1rem;
}

.input-block label,
.option-item label {
  display: block;
  font-size: 0.9rem;
  font-weight: 600;
  color: #444;
  margin-bottom: 0.4rem;
}

#input-text {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1.5px solid #ccc;
  border-radius: 7px;
  resize: vertical;
  min-height: 130px;
  transition: border-color 0.2s;
  -webkit-appearance: none;
}

#input-text:focus {
  outline: none;
  border-color: #1a5276;
}

.char-count {
  text-align: right;
  font-size: 0.8rem;
  color: #888;
  margin-top: 0.3rem;
}

.char-count.over {
  color: #c0392b;
  font-weight: 600;
}

/* ========== Options Block ========== */
.options-block {
  display: grid;
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.option-item select {
  width: 100%;
  padding: 0.65rem 0.75rem;
  font-size: 0.95rem;
  font-family: inherit;
  border: 1.5px solid #ccc;
  border-radius: 7px;
  background: white;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1l5 5 5-5' stroke='%23666' stroke-width='2' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  padding-right: 2rem;
  min-height: 44px;
}

.option-item select:focus {
  outline: none;
  border-color: #1a5276;
}

/* ========== Buttons ========== */
.btn-primary {
  display: block;
  width: 100%;
  padding: 1rem;
  font-size: 1.05rem;
  font-weight: 700;
  font-family: inherit;
  background: #1a5276;
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  min-height: 56px;
  transition: background 0.2s, transform 0.1s;
  -webkit-tap-highlight-color: transparent;
}

.btn-primary:hover {
  background: #21618c;
}

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

.btn-primary:disabled {
  background: #aaa;
  cursor: not-allowed;
}

.btn-copy {
  padding: 0.5rem 1.1rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  background: #1a5276;
  color: white;
  border: none;
  border-radius: 6px;
  cursor: pointer;
  min-height: 44px;
  transition: background 0.2s;
  white-space: nowrap;
}

.btn-copy:hover {
  background: #21618c;
}

.btn-copy.copied {
  background: #27ae60;
}

/* ========== Loading ========== */
.loading {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 1rem;
  color: #555;
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

.loading-spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2.5px solid #ccc;
  border-top-color: #1a5276;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  flex-shrink: 0;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ========== Error ========== */
.error-msg {
  margin-top: 0.75rem;
  padding: 0.85rem 1rem;
  background: #fdf2f2;
  border: 1px solid #f5c6c6;
  border-radius: 7px;
  color: #c0392b;
  font-size: 0.9rem;
}

/* ========== Output Block ========== */
.output-block {
  margin-top: 1.25rem;
}

.output-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.6rem;
  gap: 0.5rem;
}

.output-label {
  font-size: 1rem;
  font-weight: 700;
  color: #1a5276;
}

/* Preview */
.preview-area {
  background: #f0f4f8;
  border-radius: 7px;
  padding: 1rem;
  margin-bottom: 1rem;
  font-size: 1.1rem;
  line-height: 2.2;
  word-break: break-all;
  min-height: 60px;
  border: 1px solid #dde3ea;
}

.preview-area ruby {
  ruby-align: center;
}

.preview-area rt {
  font-size: 0.55em;
  color: #555;
}

/* Code block */
.code-block-wrap {
  position: relative;
}

.code-label {
  display: block;
  font-size: 0.82rem;
  color: #666;
  margin-bottom: 0.3rem;
  font-weight: 600;
}

.output-text {
  width: 100%;
  padding: 0.75rem;
  font-size: 0.85rem;
  font-family: "Courier New", "Menlo", monospace;
  border: 1.5px solid #ccc;
  border-radius: 7px;
  background: #f9f9f9;
  color: #333;
  resize: vertical;
  min-height: 110px;
  -webkit-appearance: none;
}

.output-text:focus {
  outline: none;
  border-color: #1a5276;
}

/* ========== How-To Section ========== */
.howto-section {
  margin-top: 1.5rem;
  background: white;
  border-radius: 10px;
  padding: 1.25rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.07);
}

.howto-section h2 {
  font-size: 1rem;
  font-weight: 700;
  color: #1a5276;
  margin-top: 1.5rem;
  margin-bottom: 0.6rem;
  padding-bottom: 0.3rem;
  border-bottom: 2px solid #d5e8f5;
}

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

.howto-section ol {
  padding-left: 1.3rem;
  font-size: 0.93rem;
  color: #444;
}

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

.howto-section p {
  font-size: 0.93rem;
  color: #444;
  line-height: 1.75;
}

.howto-section code {
  font-family: "Courier New", monospace;
  font-size: 0.82em;
  background: #f0f4f8;
  padding: 0.15em 0.35em;
  border-radius: 3px;
  color: #1a5276;
}

/* Format table */
.format-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
  margin-top: 0.5rem;
}

.format-table th,
.format-table td {
  padding: 0.6rem 0.7rem;
  border: 1px solid #dde3ea;
  text-align: left;
  vertical-align: top;
}

.format-table th {
  background: #f0f4f8;
  font-weight: 700;
  color: #1a5276;
}

.format-table tr:nth-child(even) td {
  background: #f8fafc;
}

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

.site-footer a {
  color: #666;
  text-decoration: none;
  min-height: 44px;
  display: inline-block;
  line-height: 44px;
}

.site-footer a:hover {
  color: #333;
  text-decoration: underline;
}

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

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

  .site-header h1 {
    font-size: 1.6rem;
  }

  main {
    padding: 1.5rem 2rem;
  }

  .tool-section {
    padding: 1.75rem 2rem;
  }

  .options-block {
    grid-template-columns: 1fr 1fr;
  }

  .howto-section {
    padding: 1.75rem 2rem;
  }

  .format-table {
    font-size: 0.9rem;
  }
}
