:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-soft: #f8fafc;
  --border: #d9e1ec;
  --text: #1f2937;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-strong: #1d4ed8;
  --danger: #b91c1c;
  --shadow: rgba(15, 23, 42, 0.10);
  --editor-bg: #ffffff;
  --editor-text: #111827;
  --line-bg: #f1f5f9;
  --line-text: #64748b;
  --footer-bg: #eef3f7;
}

* {
  box-sizing: border-box;
}

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

body {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Meiryo", sans-serif;
}

body.theme-soft {
  --bg: #fbf7ef;
  --surface: #fffdf8;
  --surface-soft: #fff8ea;
  --border: #eadcc1;
  --accent: #0f766e;
  --accent-strong: #0d5f58;
  --editor-bg: #fffdf6;
  --line-bg: #f6eddc;
  --footer-bg: #f2eee5;
}

body.theme-dark {
  --bg: #111827;
  --surface: #1f2937;
  --surface-soft: #273244;
  --border: #475569;
  --text: #e5e7eb;
  --muted: #cbd5e1;
  --accent: #60a5fa;
  --accent-strong: #93c5fd;
  --editor-bg: #0f172a;
  --editor-text: #f8fafc;
  --line-bg: #182235;
  --line-text: #94a3b8;
  --footer-bg: #0f172a;
  --shadow: rgba(0, 0, 0, 0.25);
}

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

button {
  cursor: pointer;
}

.app-wrapper {
  flex: 1;
  width: 100%;
  padding: 14px;
  display: flex;
  justify-content: center;
}

.app-wrapper.dragover {
  outline: 4px dashed var(--accent);
  outline-offset: -10px;
}

.app {
  width: 100%;
  max-width: 1180px;
  min-height: calc(100vh - 130px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 12px 28px var(--shadow);
}

.app-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  color: white;
  background: linear-gradient(90deg, #1d4ed8, #0891b2);
}

.app-header h1 {
  margin: 0 0 4px;
  font-size: 1.15rem;
  font-weight: 700;
}

.app-header p {
  margin: 0;
  font-size: 0.82rem;
  opacity: 0.92;
}

.header-badge {
  flex: 0 0 auto;
  padding: 5px 10px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.18);
  border: 1px solid rgba(255, 255, 255, 0.35);
  font-size: 0.8rem;
}

.toolbar, .setting-panel, .search-panel {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-soft);
}

.toolbar button,
.setting-panel button,
.search-panel button,
.modal-buttons button,
.context-menu button {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 12px;
  background: var(--surface);
  color: var(--text);
  line-height: 1.1;
  transition: transform 0.06s ease, background 0.12s ease, border-color 0.12s ease;
}

.toolbar button:hover,
.setting-panel button:hover,
.search-panel button:hover,
.modal-buttons button:hover,
.context-menu button:hover {
  border-color: var(--accent);
  background: rgba(37, 99, 235, 0.09);
}

.toolbar button:active,
.setting-panel button:active,
.search-panel button:active,
.modal-buttons button:active {
  transform: translateY(1px);
}

.toolbar-separator {
  width: 1px;
  height: 24px;
  background: var(--border);
}

.tab-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  overflow-x: auto;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.tab {
  min-width: 0;
  max-width: 220px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 6px 10px 6px 12px;
  background: var(--surface-soft);
  color: var(--text);
  white-space: nowrap;
}

.tab.active {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.tab-title {
  overflow: hidden;
  text-overflow: ellipsis;
}

.tab-dirty {
  font-weight: 700;
  color: #f97316;
}

.tab.active .tab-dirty {
  color: #fed7aa;
}

.close-tab {
  width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: inherit;
}

.close-tab:hover {
  background: rgba(255, 255, 255, 0.23);
}

.add-tab {
  border-style: dashed;
  font-weight: 700;
}

.search-panel {
  display: none;
}

.search-panel.open {
  display: block;
}

.search-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 3px 0;
}

.search-panel label,
.setting-panel label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 0.85rem;
}

.search-panel input[type="search"],
.search-panel input[type="text"],
.setting-panel select {
  min-width: 160px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 8px;
  background: var(--surface);
  color: var(--text);
}

.check-label {
  user-select: none;
}

.search-info {
  min-width: 72px;
  color: var(--muted);
  font-size: 0.85rem;
}

.editor-shell {
  position: relative;
  flex: 1;
  min-height: 360px;
  display: grid;
  grid-template-columns: auto 1fr;
  background: var(--editor-bg);
  overflow: hidden;
}

.line-numbers {
  min-width: 48px;
  margin: 0;
  padding: 12px 8px;
  overflow: hidden;
  border-right: 1px solid var(--border);
  background: var(--line-bg);
  color: var(--line-text);
  text-align: right;
  user-select: none;
  white-space: pre;
  font-family: Consolas, "SFMono-Regular", "Liberation Mono", Menlo, monospace;
  font-size: 15px;
  line-height: 1.65;
}

.editor-shell.hide-line-numbers {
  grid-template-columns: 1fr;
}

.editor-shell.hide-line-numbers .line-numbers {
  display: none;
}

#editor {
  width: 100%;
  height: 100%;
  min-height: 360px;
  resize: none;
  border: none;
  outline: none;
  padding: 12px 14px;
  background: var(--editor-bg);
  color: var(--editor-text);
  font-family: "MS Gothic", "ＭＳ ゴシック", Consolas, "SFMono-Regular", "Liberation Mono", monospace;
  font-size: 15px;
  line-height: 1.65;
  tab-size: 2;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  caret-color: transparent;
}

#editor.no-wrap {
  white-space: pre;
  overflow-wrap: normal;
}


.virtual-caret {
  position: absolute;
  z-index: 5;
  display: none;
  width: 2px;
  pointer-events: none;
  background: var(--editor-text);
  animation: virtual-caret-blink 1s steps(1, end) infinite;
}

.virtual-caret.visible {
  display: block;
}

#editor.virtual-caret-active {
  caret-color: transparent;
}

@keyframes virtual-caret-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.status-bar {
  min-height: 31px;
  padding: 7px 12px;
  border-top: 1px solid var(--border);
  background: var(--surface-soft);
  color: var(--muted);
  font-size: 0.78rem;
  text-align: right;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(15, 23, 42, 0.43);
}

.modal-backdrop.open {
  display: flex;
}

.modal {
  width: min(420px, calc(100vw - 28px));
  padding: 18px;
  background: var(--surface);
  color: var(--text);
  border-radius: 16px;
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.30);
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 1rem;
}

.modal p {
  margin: 0 0 12px;
  white-space: pre-line;
  color: var(--muted);
}

.modal-buttons {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.modal-buttons .primary {
  color: white;
  background: var(--accent);
  border-color: var(--accent);
}

.modal-buttons .danger {
  color: white;
  background: var(--danger);
  border-color: var(--danger);
}

.context-menu {
  position: fixed;
  z-index: 120;
  display: none;
  min-width: 168px;
  padding: 6px;
  border: 1px solid var(--border);
  border-radius: 12px;
  background: var(--surface);
  box-shadow: 0 12px 28px var(--shadow);
}

.context-menu.open {
  display: block;
}

.context-menu button {
  width: 100%;
  display: block;
  border: none;
  border-radius: 8px;
  padding: 8px 10px;
  text-align: left;
  background: transparent;
}

.context-menu hr {
  border: 0;
  border-top: 1px solid var(--border);
  margin: 5px 0;
}

.app-footer {
  margin-top: auto;
  padding: 8px 10px 12px;
  border-top: 1px solid #d5dee9;
  background: var(--footer-bg);
  color: blue;
  text-align: center;
  font-size: 0.76rem;
}

.app-footer p {
  margin: 0 0 5px;
  color: blue;
}

.app-footer a {
  color: blue;
  text-decoration: none;
}

.ad-area {
  max-width: 980px;
  min-height: 42px;
  margin: 0 auto;
  padding-top: 3px;
  border-top: 1px solid rgba(37, 99, 235, 0.12);
}

@media (max-width: 760px) {
  .app-wrapper {
    padding: 6px;
  }

  .app {
    min-height: calc(100vh - 98px);
    border-radius: 12px;
  }

  .app-header {
    padding: 10px 12px;
    align-items: flex-start;
  }

  .app-header h1 {
    font-size: 1rem;
  }

  .toolbar, .setting-panel, .search-panel {
    gap: 6px;
    padding: 7px;
  }

  .toolbar button,
  .setting-panel button,
  .search-panel button {
    padding: 6px 9px;
    font-size: 0.82rem;
  }

  .editor-shell, #editor {
    min-height: 330px;
  }

  .line-numbers, #editor {
    font-size: 14px;
  }

  
.virtual-caret {
  position: absolute;
  z-index: 5;
  display: none;
  width: 2px;
  pointer-events: none;
  background: var(--editor-text);
  animation: virtual-caret-blink 1s steps(1, end) infinite;
}

.virtual-caret.visible {
  display: block;
}

#editor.virtual-caret-active {
  caret-color: transparent;
}

@keyframes virtual-caret-blink {
  0%, 49% { opacity: 1; }
  50%, 100% { opacity: 0; }
}

.status-bar {
    text-align: left;
  }
}

@page {
  size: auto;
  margin: 0;
}

@media print {
  html,
  body {
    margin: 0 !important;
    padding: 0 !important;
    background: #fff !important;
    color: #000 !important;
  }

  body > *:not(#printOnly) {
    display: none !important;
  }

  #printOnly {
    display: block !important;
    box-sizing: border-box;
    width: 100%;
    min-height: 100vh;
    margin: 0 !important;
    padding: 15mm 18mm !important;
    border: 0 !important;
    outline: 0 !important;
    overflow: visible !important;
    white-space: pre-wrap !important;
    overflow-wrap: anywhere;
    word-break: break-word;
    background: #fff !important;
    color: #000 !important;
    font-family: "Yu Gothic", "Hiragino Kaku Gothic ProN", "Noto Sans JP", sans-serif;
    line-height: 1.65;
    scrollbar-width: none;
  }

  #printOnly::-webkit-scrollbar {
    display: none !important;
  }
}


.print-only {
  display: none;
}
