/* ===== Reset & Base ===== */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --color-primary: #2563eb;
  --color-primary-dark: #1d4ed8;
  --color-danger: #dc2626;
  --color-danger-dark: #b91c1c;
  --color-surface: #ffffff;
  --color-bg: #f1f5f9;
  --color-border: #e2e8f0;
  --color-text: #1e293b;
  --color-text-muted: #64748b;
  --color-header-bg: #0f172a;
  --radius: 8px;
  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);
}

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

/* ===== Utility ===== */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
}

/* ===== Header ===== */
.app-header {
  background: var(--color-header-bg);
  color: #fff;
  padding: 1.25rem 1rem;
  text-align: center;
}

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

.app-title {
  font-size: 1.15rem;
  font-weight: 700;
  line-height: 1.3;
}

.app-subtitle {
  font-size: 0.875rem;
  opacity: 0.8;
  margin-top: 0.25rem;
}

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

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

/* ===== Toolbar ===== */
.toolbar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.75rem;
  box-shadow: var(--shadow);
}

.toolbar-group {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

.toolbar-select {
  height: 44px;
  padding: 0 0.75rem;
  font-size: 0.9rem;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: #fff;
  cursor: pointer;
  min-width: 160px;
}

.toolbar-status {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  font-size: 0.85rem;
  color: var(--color-text-muted);
  margin-left: auto;
  flex-wrap: wrap;
}

.save-indicator {
  font-size: 0.8rem;
  color: #16a34a;
  font-weight: 600;
}

/* ===== Buttons ===== */
.btn {
  height: 44px;
  padding: 0 1rem;
  font-size: 0.9rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
  white-space: nowrap;
  min-width: 44px;
}

.btn--primary {
  background: var(--color-primary);
  color: #fff;
}

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

.btn--secondary {
  background: #475569;
  color: #fff;
}

.btn--secondary:hover {
  background: #334155;
}

.btn--danger {
  background: var(--color-danger);
  color: #fff;
}

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

/* ===== Editor Area ===== */
.editor-area {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

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

.pane-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.75rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--color-border);
}

.pane-label {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--color-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.pane-hint {
  font-size: 0.78rem;
  color: #94a3b8;
}

/* ===== Markdown Textarea ===== */
.md-textarea {
  width: 100%;
  height: 320px;
  padding: 1rem;
  font-family: "SF Mono", "Fira Code", "Consolas", monospace;
  font-size: 0.9rem;
  line-height: 1.7;
  border: none;
  resize: vertical;
  outline: none;
  color: #1e293b;
  background: #fff;
}

/* ===== Slide Preview ===== */
.slide-preview {
  aspect-ratio: 16 / 9;
  padding: 1.5rem 2rem;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  justify-content: center;
  position: relative;
}

/* ===== Slide Nav (Preview) ===== */
.slide-nav {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.5rem;
  background: #f8fafc;
  border-top: 1px solid var(--color-border);
}

.slide-nav-btn {
  height: 44px;
  min-width: 44px;
  padding: 0 1rem;
  font-size: 1.1rem;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.slide-nav-btn:hover {
  background: var(--color-primary-dark);
}

/* ===== Slide Themes ===== */
.slide-preview,
.thumb-inner,
.present-slide {
  font-family: -apple-system, BlinkMacSystemFont, "Noto Sans JP", sans-serif;
  line-height: 1.5;
}

/* Dark theme */
.theme-dark {
  background: #1e1e2e;
  color: #cdd6f4;
}

.theme-dark h1, .theme-dark h2, .theme-dark h3 {
  color: #89b4fa;
}

.theme-dark code, .theme-dark pre {
  background: #313244;
  color: #a6e3a1;
}

/* Light theme */
.theme-light {
  background: #ffffff;
  color: #1e293b;
}

.theme-light h1, .theme-light h2, .theme-light h3 {
  color: #0f172a;
}

.theme-light code, .theme-light pre {
  background: #f1f5f9;
  color: #0f172a;
}

/* Blue theme */
.theme-blue {
  background: #1e3a5f;
  color: #e0f2fe;
}

.theme-blue h1, .theme-blue h2, .theme-blue h3 {
  color: #7dd3fc;
}

.theme-blue code, .theme-blue pre {
  background: #164e8a;
  color: #bae6fd;
}

/* Green theme */
.theme-green {
  background: #14432a;
  color: #d1fae5;
}

.theme-green h1, .theme-green h2, .theme-green h3 {
  color: #6ee7b7;
}

.theme-green code, .theme-green pre {
  background: #065f46;
  color: #a7f3d0;
}

/* ===== Slide Content Typography ===== */
.slide-preview h1, .present-slide h1 {
  font-size: clamp(1.4rem, 3vw, 2.5rem);
  margin-bottom: 0.75rem;
  font-weight: 700;
}

.slide-preview h2, .present-slide h2 {
  font-size: clamp(1.1rem, 2.2vw, 1.8rem);
  margin-bottom: 0.5rem;
  font-weight: 600;
}

.slide-preview h3, .present-slide h3 {
  font-size: clamp(0.95rem, 1.8vw, 1.4rem);
  margin-bottom: 0.4rem;
  font-weight: 600;
}

.slide-preview p, .present-slide p {
  font-size: clamp(0.85rem, 1.4vw, 1.1rem);
  margin-bottom: 0.5rem;
}

.slide-preview ul, .slide-preview ol,
.present-slide ul, .present-slide ol {
  padding-left: 1.5rem;
  margin-bottom: 0.5rem;
}

.slide-preview li, .present-slide li {
  font-size: clamp(0.85rem, 1.4vw, 1.1rem);
  margin-bottom: 0.3rem;
}

.slide-preview pre, .present-slide pre {
  padding: 0.75rem 1rem;
  border-radius: 6px;
  font-size: clamp(0.7rem, 1.1vw, 0.9rem);
  overflow: auto;
  margin-bottom: 0.5rem;
}

.slide-preview code:not(pre code), .present-slide code:not(pre code) {
  padding: 0.1rem 0.35rem;
  border-radius: 4px;
  font-size: 0.88em;
}

.slide-preview table, .present-slide table {
  border-collapse: collapse;
  font-size: clamp(0.75rem, 1.2vw, 0.9rem);
  margin-bottom: 0.5rem;
  width: 100%;
}

.slide-preview th, .present-slide th,
.slide-preview td, .present-slide td {
  padding: 0.3rem 0.6rem;
  border: 1px solid rgba(255,255,255,0.2);
}

.theme-light .slide-preview th, .theme-light .present-slide th,
.theme-light .slide-preview td, .theme-light .present-slide td {
  border-color: #cbd5e1;
}

/* ===== Thumbnails ===== */
.thumbnails-section {
  margin-top: 1.5rem;
}

.section-heading {
  font-size: 1rem;
  font-weight: 700;
  color: var(--color-text-muted);
  margin-bottom: 0.75rem;
  padding-bottom: 0.5rem;
  border-bottom: 2px solid var(--color-border);
}

.thumbnails-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.thumb-item {
  width: calc(50% - 0.375rem);
  cursor: pointer;
  border: 2px solid var(--color-border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s;
  background: var(--color-surface);
  box-shadow: var(--shadow);
}

.thumb-item:hover {
  border-color: var(--color-primary);
  box-shadow: var(--shadow-md);
}

.thumb-item.active {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.2);
}

.thumb-number {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--color-text-muted);
  padding: 0.25rem 0.5rem;
  background: #f8fafc;
  border-bottom: 1px solid var(--color-border);
}

.thumb-inner {
  aspect-ratio: 16 / 9;
  padding: 0.5rem 0.75rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
  transform-origin: top left;
}

/* サムネイルのフォントを縮小 */
.thumb-inner h1 { font-size: 0.7rem; font-weight: 700; margin-bottom: 0.2rem; }
.thumb-inner h2 { font-size: 0.6rem; font-weight: 600; margin-bottom: 0.15rem; }
.thumb-inner h3 { font-size: 0.55rem; font-weight: 600; }
.thumb-inner p, .thumb-inner li { font-size: 0.5rem; margin-bottom: 0.1rem; }
.thumb-inner pre, .thumb-inner code { font-size: 0.45rem; }
.thumb-inner ul, .thumb-inner ol { padding-left: 0.75rem; }

/* ===== Full-Screen Presentation ===== */
.present-overlay {
  position: fixed;
  inset: 0;
  background: #000;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.present-overlay[hidden] {
  display: none;
}

.present-slide {
  width: min(90vw, calc(90vh * 16 / 9));
  aspect-ratio: 16 / 9;
  padding: 3rem 4rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-md);
}

.present-controls {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-top: 1rem;
}

.present-btn {
  height: 44px;
  min-width: 44px;
  padding: 0 1rem;
  font-size: 1rem;
  background: rgba(255,255,255,0.15);
  color: #fff;
  border: 1px solid rgba(255,255,255,0.3);
  border-radius: var(--radius);
  cursor: pointer;
  transition: background 0.15s;
}

.present-btn:hover {
  background: rgba(255,255,255,0.3);
}

.present-btn--exit {
  background: rgba(220,38,38,0.7);
  border-color: rgba(220,38,38,0.9);
}

.present-btn--exit:hover {
  background: rgba(220,38,38,0.9);
}

.present-counter {
  color: #fff;
  font-size: 0.9rem;
  font-weight: 600;
  min-width: 60px;
  text-align: center;
}

.present-hint {
  color: rgba(255,255,255,0.45);
  font-size: 0.75rem;
  margin-top: 0.5rem;
}

/* ===== How-to Section ===== */
.howto-section {
  margin-top: 2rem;
  background: var(--color-surface);
  border-radius: var(--radius);
  padding: 1.5rem;
  box-shadow: var(--shadow);
}

.howto-section h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: #0f172a;
  margin-top: 1.5rem;
  margin-bottom: 0.75rem;
  padding-bottom: 0.4rem;
  border-bottom: 2px solid var(--color-border);
}

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

.howto-list {
  padding-left: 1.5rem;
  color: #475569;
  font-size: 0.95rem;
}

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

.howto-section p {
  color: #475569;
  font-size: 0.95rem;
  line-height: 1.7;
  margin-bottom: 0.75rem;
}

.howto-section code {
  background: #f1f5f9;
  padding: 0.1rem 0.4rem;
  border-radius: 4px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.88em;
  color: #0f172a;
}

/* ===== Markdown Table (howto) ===== */
.md-table {
  border-collapse: collapse;
  width: 100%;
  font-size: 0.9rem;
  margin-top: 0.75rem;
}

.md-table th, .md-table td {
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--color-border);
  text-align: left;
}

.md-table th {
  background: #f8fafc;
  font-weight: 700;
  color: #0f172a;
}

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

.footer-nav {
  display: flex;
  justify-content: center;
  gap: 1.5rem;
  margin-bottom: 0.5rem;
  flex-wrap: wrap;
}

.footer-nav a {
  color: #64748b;
  text-decoration: none;
}

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

/* ===== Print / PDF ===== */
@media print {
  .app-header, .toolbar, .editor-pane, .thumbnails-section,
  .howto-section, .app-footer, .ad-unit, .slide-nav,
  .present-overlay, .pane-header {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .editor-area {
    display: block;
  }

  .preview-pane {
    border: none;
    box-shadow: none;
    page-break-after: always;
  }

  .slide-preview {
    aspect-ratio: 16 / 9;
    width: 100%;
    page-break-inside: avoid;
  }

  main {
    padding: 0;
    max-width: 100%;
  }
}

/* ===== Responsive: Tablet+ ===== */
@media (min-width: 768px) {
  .app-title {
    font-size: 1.4rem;
  }

  .editor-area {
    flex-direction: row;
    align-items: stretch;
  }

  .editor-pane {
    flex: 0 0 44%;
  }

  .preview-pane {
    flex: 1;
  }

  .md-textarea {
    height: 100%;
    min-height: 400px;
  }

  .thumb-item {
    width: calc(33.333% - 0.5rem);
  }
}

@media (min-width: 1024px) {
  .app-title {
    font-size: 1.6rem;
  }

  .thumb-item {
    width: calc(25% - 0.5625rem);
  }
}
