:root {
  --primary: #1468e8;
  --primary-dark: #0f4fb3;
  --primary-soft: #eaf2ff;
  --text: #1e293b;
  --muted: #64748b;
  --line: #d8e0ea;
  --line-strong: #b8c5d6;
  --surface: #ffffff;
  --surface-soft: #f5f8fc;
  --page: #eef3f8;
  --success: #087a3e;
  --warning: #9a5b00;
  --danger: #c62828;
  --shadow: 0 10px 30px rgba(30, 41, 59, 0.08);
  --radius: 14px;
}

* {
  box-sizing: border-box;
}

/* hidden属性は各コンポーネントのdisplay指定より常に優先する */
[hidden] {
  display: none !important;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-width: 320px;
  background: var(--page);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans JP", "Yu Gothic", sans-serif;
  line-height: 1.6;
}

button,
input,
textarea,
select {
  font: inherit;
}

button,
select,
input[type="file"] {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid rgba(20, 104, 232, 0.22);
  outline-offset: 2px;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  min-height: 74px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.96);
  backdrop-filter: blur(12px);
}

.app-title-wrap {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 280px;
}

.app-mark {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  border-radius: 12px;
  background: linear-gradient(135deg, #eaf2ff, #d7e8ff);
  color: var(--primary);
  font-weight: 800;
  font-size: 1rem;
  letter-spacing: -0.08em;
}

.app-title-wrap h1 {
  margin: 0;
  font-size: clamp(1.2rem, 2vw, 1.75rem);
  line-height: 1.25;
}

.app-title-wrap p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.header-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.button {
  min-height: 40px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 10px;
  cursor: pointer;
  font-weight: 700;
  transition: transform 0.05s ease, background-color 0.2s ease, border-color 0.2s ease, opacity 0.2s ease;
}

.button:hover:not(:disabled) {
  transform: translateY(-1px);
}

.button:active:not(:disabled) {
  transform: translateY(0);
}

.button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
}

.button-primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #ffffff;
}

.button-primary:hover:not(:disabled) {
  background: var(--primary-dark);
  border-color: var(--primary-dark);
}

.button-outline {
  border-color: var(--line-strong);
  background: #ffffff;
  color: var(--text);
}

.button-outline:hover:not(:disabled) {
  border-color: var(--primary);
  color: var(--primary-dark);
}

.button-muted {
  border-color: var(--line);
  background: var(--surface-soft);
  color: #334155;
}

.button-wide {
  width: 100%;
  margin-top: 14px;
}

.app-main {
  display: grid;
  grid-template-columns: minmax(0, 1.45fr) minmax(360px, 0.75fr);
  gap: 12px;
  width: 100%;
  min-height: calc(100vh - 126px);
  padding: 12px;
}

.preview-pane,
.editor-pane {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.preview-pane {
  display: flex;
  flex-direction: column;
}

.editor-pane {
  display: flex;
  flex-direction: column;
}

.pane-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  min-height: 70px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
  background: #ffffff;
}

.pane-header h2 {
  margin: 0;
  font-size: 1.05rem;
}

.pane-header p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
}

.preview-tools {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.select-label {
  color: var(--muted);
  font-size: 0.76rem;
  white-space: nowrap;
}

#htmlSelect {
  min-width: 180px;
  max-width: 280px;
  height: 38px;
  padding: 0 34px 0 10px;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #ffffff;
  color: var(--text);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 1px solid var(--line-strong);
  border-radius: 9px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  font-size: 1.25rem;
}

.icon-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.notice-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 9px 14px;
  border-bottom: 1px solid #efd49b;
  background: #fff8e8;
  color: #6d4700;
  font-size: 0.82rem;
}

.notice-action {
  flex: 0 0 auto;
  min-height: 32px;
  padding: 5px 10px;
  border: 1px solid #c88a19;
  border-radius: 8px;
  background: #ffffff;
  color: #754800;
  cursor: pointer;
  font-size: 0.76rem;
  font-weight: 800;
}

.notice-action:hover {
  background: #fff1cc;
}

.preview-shell {
  position: relative;
  flex: 1;
  min-height: 560px;
  background: #f2f5f8;
}

#previewFrame {
  width: 100%;
  height: 100%;
  min-height: 560px;
  border: 0;
  background: #ffffff;
}

.empty-state {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  justify-items: center;
  gap: 10px;
  padding: 28px;
  text-align: center;
}

.empty-icon {
  display: grid;
  place-items: center;
  width: 92px;
  height: 72px;
  border: 2px dashed #9cbce8;
  border-radius: 16px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.08em;
}

.empty-state h3 {
  margin: 4px 0 0;
  font-size: 1.2rem;
}

.empty-state p {
  max-width: 550px;
  margin: 0;
  color: var(--muted);
}

.empty-actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  margin-top: 8px;
}

.drop-start-guide {
  display: grid;
  justify-items: center;
  gap: 3px;
  width: min(100%, 560px);
  margin-top: 8px;
  padding: 16px 20px;
  border: 2px dashed #7aa8e8;
  border-radius: 12px;
  background: rgba(234, 242, 255, 0.78);
  color: var(--primary-dark);
}

.drop-start-guide strong {
  font-size: 0.96rem;
}

.drop-start-guide > span:last-child {
  color: var(--muted);
  font-size: 0.76rem;
}

.drop-start-icon {
  font-size: 1.55rem;
  line-height: 1;
}

.drop-overlay {
  position: absolute;
  inset: 10px;
  z-index: 30;
  display: grid;
  place-items: center;
  border: 3px dashed #1468e8;
  border-radius: 14px;
  background: rgba(234, 242, 255, 0.95);
  backdrop-filter: blur(4px);
}

.drop-overlay-card {
  display: grid;
  justify-items: center;
  gap: 5px;
  max-width: 520px;
  padding: 28px;
  color: var(--primary-dark);
  text-align: center;
}

.drop-overlay-card strong {
  font-size: 1.25rem;
}

.drop-overlay-card span:last-child {
  color: #405169;
  font-size: 0.84rem;
}

.drop-overlay-icon {
  display: grid;
  place-items: center;
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: #ffffff;
  box-shadow: 0 8px 24px rgba(20, 104, 232, 0.18);
  font-size: 2rem;
}

.editor-header {
  flex-shrink: 0;
}

.selection-badge {
  max-width: 180px;
  padding: 5px 10px;
  border-radius: 999px;
  background: #eef2f7;
  color: #526174;
  font-size: 0.75rem;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.editor-scroll {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
}

.editor-empty {
  display: grid;
  justify-items: center;
  gap: 6px;
  padding: 40px 16px;
  border: 2px dashed var(--line);
  border-radius: 12px;
  background: var(--surface-soft);
  text-align: center;
}

.pointer-illustration {
  font-size: 2rem;
}

.editor-empty h3,
.editor-empty p {
  margin: 0;
}

.editor-empty p {
  max-width: 360px;
  color: var(--muted);
  font-size: 0.9rem;
}

.editor-card,
.howto-card {
  margin-bottom: 14px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #ffffff;
}

.card-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.card-heading h3 {
  margin: 2px 0 0;
  font-size: 1.05rem;
}

.card-kicker {
  color: var(--primary-dark);
  font-size: 0.72rem;
  font-weight: 800;
}

.field-label {
  display: block;
  margin: 12px 0 6px;
  color: #334155;
  font-size: 0.85rem;
  font-weight: 800;
}

textarea,
input[type="text"] {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  background: #ffffff;
  color: var(--text);
}

textarea {
  min-height: 180px;
  padding: 12px;
  resize: vertical;
  line-height: 1.7;
}

input[type="text"] {
  height: 42px;
  padding: 0 11px;
}

.field-help {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.paragraph-move-panel {
  margin-top: 14px;
  padding: 13px;
  border: 1px solid #c9d9ef;
  border-radius: 10px;
  background: #f7faff;
}

.paragraph-move-heading {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.paragraph-move-heading h4 {
  margin: 0;
  font-size: 0.92rem;
}

.paragraph-move-heading p,
.paragraph-move-help {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.74rem;
}

.paragraph-move-buttons {
  display: flex;
  flex: 0 0 auto;
  gap: 7px;
}

.move-arrow-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  min-width: 76px;
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid #9cbce8;
  border-radius: 9px;
  background: #ffffff;
  color: var(--primary-dark);
  cursor: pointer;
  font-size: 1.05rem;
  font-weight: 800;
}

.move-arrow-button span {
  font-size: 0.78rem;
}

.move-arrow-button:hover:not(:disabled) {
  border-color: var(--primary);
  background: var(--primary-soft);
}

.move-arrow-button:disabled {
  cursor: not-allowed;
  opacity: 0.4;
}

.current-image-box {
  display: grid;
  place-items: center;
  min-height: 180px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background:
    linear-gradient(45deg, #f1f4f8 25%, transparent 25%),
    linear-gradient(-45deg, #f1f4f8 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #f1f4f8 75%),
    linear-gradient(-45deg, transparent 75%, #f1f4f8 75%);
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
  background-size: 16px 16px;
  overflow: hidden;
}

.current-image-box img {
  display: block;
  max-width: 100%;
  max-height: 260px;
  object-fit: contain;
}

.file-drop {
  display: grid;
  justify-items: center;
  gap: 2px;
  margin-top: 12px;
  padding: 18px;
  border: 2px dashed #9cbce8;
  border-radius: 10px;
  background: var(--primary-soft);
  color: var(--primary-dark);
  cursor: pointer;
  text-align: center;
}

.file-drop:hover {
  background: #dfebff;
}

.file-drop-title {
  font-weight: 800;
}

.file-drop-note {
  font-size: 0.76rem;
}

.selected-file-name {
  margin: 7px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  overflow-wrap: anywhere;
}

.howto-card {
  background: #f7faff;
}

.howto-card h3 {
  margin: 0 0 8px;
  color: var(--primary-dark);
  font-size: 0.95rem;
}

.howto-card ol {
  margin: 0;
  padding-left: 1.4em;
  color: #405169;
  font-size: 0.82rem;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  z-index: 100;
  max-width: min(90vw, 560px);
  padding: 10px 16px;
  border-radius: 999px;
  background: rgba(18, 30, 48, 0.94);
  color: #ffffff;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.22);
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 12px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  text-align: center;
  font-size: 0.86rem;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.site-footer {
  min-height: 40px;
  padding: 8px 12px 14px;
  border-top: 1px solid #d8e6f5;
  background: #f7faff;
  color: #1565c0;
  text-align: center;
  font-size: 0.82rem;
}

.site-footer p {
  margin: 0;
}

.site-footer a {
  color: #1565c0;
  font-weight: 800;
  text-decoration: none;
}

.site-footer a:hover {
  color: #0d47a1;
}

@media (max-width: 1180px) {
  .app-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .header-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .app-main {
    min-height: auto;
    grid-template-columns: 1fr;
  }

  .preview-shell,
  #previewFrame {
    min-height: 680px;
  }
}

@media (max-width: 720px) {
  .app-header {
    position: static;
    padding: 10px;
  }

  .app-title-wrap {
    min-width: 0;
  }

  .app-title-wrap p {
    display: none;
  }

  .app-mark {
    width: 42px;
    height: 42px;
  }

  .header-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .header-actions .button {
    width: 100%;
    padding-inline: 8px;
    font-size: 0.82rem;
  }

  .app-main {
    padding: 8px;
  }

  .pane-header {
    align-items: flex-start;
    flex-direction: column;
  }

  .preview-tools {
    width: 100%;
  }

  .select-label {
    display: none;
  }

  #htmlSelect {
    flex: 1;
    min-width: 0;
    max-width: none;
  }

  .preview-shell,
  #previewFrame {
    min-height: 620px;
  }
}

.ad-panel[hidden] {
  display: none !important;
  height: 0 !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
  overflow: hidden !important;
}

.ad-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-height: 28px;
  padding: 4px 8px;
  border-bottom: 1px solid #d7e6f8;
  background: #f4f8ff;
}

.ad-label {
  color: #4f6f91;
  font-size: 0.72rem;
  line-height: 1;
}

.ad-wait-message {
  margin-left: auto;
  color: #607891;
  font-size: 0.7rem;
}

.ad-close-btn {
  flex: 0 0 auto;
  min-height: 0;
  margin: 0;
  padding: 3px 8px;
  border: 0;
  border-radius: 999px;
  background: #1565c0;
  color: #ffffff;
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 700;
  line-height: 1.2;
}

.ad-close-btn:hover {
  background: #0d47a1;
}

.ad-body {
  padding: 8px;
  background: #ffffff;
}


/* 見出し・ハイパーリンク編集 */
.element-edit-panel {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fbfdff;
}

.element-edit-heading h4 {
  margin: 0;
  color: var(--text);
  font-size: 0.95rem;
}

.element-edit-heading p {
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
}

.element-edit-grid {
  display: grid;
  grid-template-columns: minmax(160px, 0.7fr) minmax(230px, 1.3fr);
  gap: 12px;
  margin-top: 12px;
}

.element-link-field input[type="text"] {
  width: 100%;
}

.link-options-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-top: 10px;
}

.link-options-row label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: #334155;
  font-size: 0.82rem;
}

.element-edit-help {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.76rem;
  line-height: 1.55;
}

@media (max-width: 720px) {
  .element-edit-grid {
    grid-template-columns: 1fr;
  }

  .link-options-row {
    align-items: stretch;
    flex-direction: column;
  }
}
