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

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

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

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

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

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

/* ===== Mobile tabs ===== */
.mobile-tabs {
  display: flex;
  border-radius: 10px 10px 0 0;
  overflow: hidden;
  background: #e2e8f0;
  gap: 2px;
  padding: 4px;
  margin-bottom: 0;
}

.mobile-tab {
  flex: 1;
  padding: 0.6rem 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  background: transparent;
  color: #64748b;
  border: none;
  cursor: pointer;
  border-radius: 6px;
  transition: all 0.2s;
  min-height: 44px;
}

.mobile-tab.active {
  background: white;
  color: #1a2a4a;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.mobile-tab:hover:not(.active) {
  background: #f1f5f9;
  color: #475569;
}

/* PC では非表示 */
@media (min-width: 768px) {
  .mobile-tabs {
    display: none;
  }
}

/* ===== Tool wrapper（2カラム） ===== */
.tool-wrapper {
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

@media (min-width: 768px) {
  .tool-wrapper {
    flex-direction: row;
    align-items: flex-start;
    gap: 1.25rem;
  }
}

/* ===== 左カラム ===== */
.col-input {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

@media (min-width: 768px) {
  .col-input {
    width: 360px;
    flex-shrink: 0;
  }
}

/* モバイル非表示制御 */
.col-input.hidden-mobile,
.col-preview.hidden-mobile {
  display: none;
}

@media (min-width: 768px) {
  .col-input.hidden-mobile,
  .col-preview.hidden-mobile {
    display: flex;
  }
}

/* ===== 設定パネル ===== */
.settings-panel {
  background: white;
  border-radius: 10px;
  padding: 0.875rem 1rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.07);
}

.settings-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.6rem;
  margin-bottom: 0.75rem;
}

.setting-group {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.setting-group label {
  font-size: 0.78rem;
  font-weight: 600;
  color: #374151;
}

.setting-group select {
  width: 100%;
  padding: 0.45rem 0.6rem;
  font-size: 0.9rem;
  border: 1.5px solid #d1d5db;
  border-radius: 6px;
  background: #f9fafb;
  color: #111827;
  cursor: pointer;
  min-height: 44px;
  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='%236b7280' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  padding-right: 1.8rem;
}

.setting-group select:focus {
  outline: none;
  border-color: #2c4a7c;
}

.btn-sample {
  width: 100%;
  padding: 0.55rem 1rem;
  font-size: 0.85rem;
  font-weight: 600;
  color: #2c4a7c;
  background: #eff6ff;
  border: 1.5px solid #bfdbfe;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.2s;
  min-height: 44px;
}

.btn-sample:hover {
  background: #dbeafe;
  border-color: #93c5fd;
}

/* ===== Textarea ===== */
.textarea-wrapper {
  background: white;
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.07);
}

textarea#input-text {
  width: 100%;
  height: 300px;
  padding: 0.875rem 1rem;
  font-size: 1rem;
  font-family: inherit;
  line-height: 1.7;
  color: #1f2937;
  border: none;
  resize: vertical;
  background: white;
}

textarea#input-text:focus {
  outline: none;
}

textarea#input-text::placeholder {
  color: #9ca3af;
  font-size: 0.9rem;
}

@media (min-width: 768px) {
  textarea#input-text {
    height: 400px;
  }
}

/* ===== 字数カウント ===== */
.count-panel {
  background: white;
  border-radius: 10px;
  padding: 0.75rem 1rem;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.07);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.count-item {
  display: flex;
  align-items: baseline;
  gap: 0.25rem;
  flex: 1;
  min-width: 80px;
}

.count-label {
  font-size: 0.72rem;
  color: #6b7280;
  white-space: nowrap;
}

.count-value {
  font-size: 1.2rem;
  font-weight: 700;
  color: #1a2a4a;
  line-height: 1;
}

.count-unit {
  font-size: 0.8rem;
  color: #374151;
}

.count-note {
  font-size: 0.7rem;
  color: #9ca3af;
  white-space: nowrap;
}

.count-divider {
  width: 1px;
  height: 2rem;
  background: #e5e7eb;
  flex-shrink: 0;
}

/* ===== 右カラム：縦書きプレビュー ===== */
.col-preview {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.preview-header {
  background: #1a2a4a;
  border-radius: 10px 10px 0 0;
  padding: 0.5rem 1rem;
  display: flex;
  align-items: center;
}

.preview-label {
  font-size: 0.8rem;
  font-weight: 600;
  color: rgba(255, 255, 255, 0.8);
  letter-spacing: 0.03em;
}

/* ===== 縦書きスクロール外枠 ===== */
.tategumi-scroll-outer {
  background: #fdf8f0;
  border: 1px solid #d1c9b8;
  border-top: none;
  border-radius: 0 0 10px 10px;
  height: 500px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.08);
  position: relative;
}

/* ===== 縦書きエリア ===== */
.tategumi-area {
  writing-mode: vertical-rl;
  text-orientation: mixed;
  font-feature-settings: "vert" 1;
  direction: rtl;
  height: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 1.5rem 1rem;
  white-space: pre-wrap;
  word-break: break-all;
  color: #1a1a1a;
  letter-spacing: 0.05em;
  /* デフォルト */
  font-size: 16px;
  line-height: 2.2;
}

/* フォントファミリー */
.tategumi-area.font-mincho {
  font-family: "Yu Mincho", "游明朝", "Hiragino Mincho ProN", "HiraMinProN-W3", "Times New Roman", serif;
}

.tategumi-area.font-gothic {
  font-family: "Yu Gothic", "游ゴシック", "Hiragino Kaku Gothic ProN", "Meiryo", sans-serif;
}

.tategumi-area.font-maru-gothic {
  font-family: "Hiragino Maru Gothic ProN", "HiraMaruProN-W4", "Rounded Mplus 1c", sans-serif;
}

/* 行間 */
.tategumi-area.lh-narrow {
  line-height: 1.8;
}

.tategumi-area.lh-normal {
  line-height: 2.2;
}

.tategumi-area.lh-wide {
  line-height: 2.8;
}

/* ルビ */
.tategumi-area ruby {
  ruby-align: center;
}

.tategumi-area rt {
  font-size: 0.5em;
}

/* プレースホルダー */
.tategumi-placeholder {
  writing-mode: vertical-rl;
  color: #a8a09a;
  font-size: 0.9rem;
  padding: 1rem;
}

/* ===== 使い方セクション ===== */
.howto-section {
  margin-top: 1.5rem;
  background: white;
  border-radius: 12px;
  padding: 1.5rem 1rem;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06);
}

.howto-section h2 {
  font-size: 1.05rem;
  color: #1a2a4a;
  margin-bottom: 0.75rem;
  margin-top: 1.5rem;
  padding-top: 1.5rem;
  border-top: 1px solid #e2e8f0;
}

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

.howto-section ol {
  padding-left: 1.25rem;
  color: #4b5563;
  font-size: 0.9rem;
}

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

.howto-section p {
  font-size: 0.9rem;
  color: #4b5563;
  line-height: 1.85;
  margin-bottom: 0.75rem;
}

.howto-section p:last-of-type {
  margin-bottom: 0;
}

.howto-section code {
  background: #f1f5f9;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  padding: 0.1em 0.4em;
  font-size: 0.85em;
  font-family: "SFMono-Regular", Consolas, "Courier New", monospace;
  color: #1a2a4a;
}

/* ===== Affiliate block ===== */
.affiliate-block {
  margin-top: 1.5rem;
  padding: 1rem;
  background: #fafafa;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
}

.affiliate-label {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 700;
  color: #9ca3af;
  border: 1px solid #d1d5db;
  padding: 0 0.35rem;
  border-radius: 3px;
  margin-bottom: 0.5rem;
}

.affiliate-desc {
  font-size: 0.85rem;
  color: #4b5563;
  margin-bottom: 0.6rem;
}

.affiliate-link {
  display: inline-block;
  font-size: 0.875rem;
  font-weight: 600;
  color: #2c4a7c;
  text-decoration: underline;
  min-height: 44px;
  line-height: 44px;
}

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

footer p {
  margin-bottom: 0.4rem;
}

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

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

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

  header h1 {
    font-size: 1.3rem;
  }

  .subtitle {
    font-size: 0.95rem;
  }

  main {
    padding: 1.5rem 2rem;
  }
}

@media (min-width: 768px) {
  .settings-row {
    grid-template-columns: repeat(4, 1fr);
  }

  .tategumi-scroll-outer {
    height: 560px;
  }
}
