:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #16324f;
  --muted: #66788a;
  --accent: #0b76c8;
  --border: #dde7ef;
  --shadow: 0 10px 30px rgba(12, 36, 58, 0.08);
  --radius: 16px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  scrollbar-width: none;
  -ms-overflow-style: none;
}

html {
  overflow: hidden;
}

body {
  margin: 0;
  font-family: "Noto Sans SC", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  overflow-y: auto;
}

html::-webkit-scrollbar,
body::-webkit-scrollbar {
  width: 0;
  height: 0;
}

.tool-page {
  display: grid;
  gap: 18px;
}

.hero h1 {
  margin: 0 0 6px;
  font-size: 24px;
  font-weight: 800;
}

.hero p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.6;
}

.grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(340px, 1fr));
  gap: 16px;
}

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.section-title {
  margin: 0 0 10px;
  font-size: 16px;
  font-weight: 700;
}

.section-sub {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.input-card {
  align-content: start;
}

.field {
  display: grid;
  gap: 6px;
  margin-bottom: 10px;
}

.field-label {
  font-size: 12px;
  color: var(--muted);
}

.field-spacer {
  visibility: hidden;
}

.input {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--border);
  border-radius: 10px;
  font-size: 14px;
  background: #fbfdff;
}

.markdown-input {
  min-height: 280px;
  resize: vertical;
  line-height: 1.55;
  font-family: Consolas, "SFMono-Regular", Menlo, Monaco, monospace;
}

.btn-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.editor-actions {
  margin-bottom: 10px;
}

.btn {
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-weight: 700;
  cursor: pointer;
  background: var(--accent);
  color: #fff;
  transition: background 150ms ease, opacity 150ms ease, transform 150ms ease;
}

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

.btn.secondary {
  background: #e6eef5;
  color: #16324f;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  transform: none;
}

.top-gap {
  margin-top: 8px;
}

.row {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.row.two-cols {
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
}

.color-control {
  display: grid;
  grid-template-columns: 72px minmax(0, 1fr);
  gap: 8px;
}

.color-input {
  min-height: 44px;
  padding: 6px;
}

.hex-input {
  font-family: Consolas, "SFMono-Regular", Menlo, Monaco, monospace;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.toggle-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 8px;
}

.checkline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0 12px;
  font-size: 13px;
  background: #fbfdff;
}

.format-note {
  margin: 4px 0 10px;
  border: 1px solid #dce8f2;
  border-radius: 10px;
  background: #fcfeff;
  padding: 8px 10px;
}

.format-note-title,
.panel-title {
  font-size: 12px;
  font-weight: 700;
  color: #274c72;
}

.panel-title {
  margin: 2px 0 8px;
}

.format-note ul {
  margin: 6px 0 0;
  padding-left: 18px;
  font-size: 12px;
  color: #4e6479;
  line-height: 1.55;
}

.status-box {
  min-height: 44px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  border-radius: 10px;
  border: 1px solid #d7e8f4;
  background: #f8fcff;
  color: #27516f;
  font-size: 13px;
  line-height: 1.45;
}

.align-group {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.field:has(#selection-status),
.field:has(#table-status) {
  display: none;
}

.row.two-cols:has(#selection-status) {
  grid-template-columns: 1fr;
}

.align-btn.is-active {
  background: #0b76c8;
  color: #fff;
}

.result-meta {
  font-size: 13px;
  color: var(--muted);
  margin-top: 10px;
  line-height: 1.6;
}

.msg {
  font-size: 13px;
  color: #b45309;
  min-height: 18px;
  margin-top: 8px;
}

.preview-shell {
  margin-top: 14px;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 18px;
  background: #ffffff;
}

.preview-stage {
  overflow: auto;
  border-radius: 14px;
  padding: 24px;
  background-color: #f8fafc;
  background-image:
    linear-gradient(45deg, rgba(148, 163, 184, 0.14) 25%, transparent 25%),
    linear-gradient(-45deg, rgba(148, 163, 184, 0.14) 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, rgba(148, 163, 184, 0.14) 75%),
    linear-gradient(-45deg, transparent 75%, rgba(148, 163, 184, 0.14) 75%);
  background-size: 24px 24px;
  background-position: 0 0, 0 12px, 12px -12px, -12px 0;
}

.rule-sheet {
  --sheet-width: 360px;
  --sheet-text: #014b88;
  --content-font-size: 14px;
  --table-font-size: 14px;
  --content-line-height: 1.5;
  --content-spacing: calc(var(--content-font-size) * 0.5);
  --list-item-spacing: calc(var(--content-font-size) * 0.5);
  --sheet-side-padding: calc(var(--content-font-size) * 0.75);
  --table-border: #2bc2ff;
  --header-row-fill: #72d0ff;
  --header-row-text: #014b88;
  --first-column-fill: #ceefff;
  --first-column-text: #014b87;
  --body-cell-fill: #fffdf9;
  --body-cell-text: #014b87;
  --table-text-align: left;
  --selection-outline: #0b76c8;
  --selection-fill: rgba(11, 118, 200, 0.12);
  --guide-fill: #e5f6ff;
  --guide-border: #9bdcff;
  --guide-text: #19527b;

  width: var(--sheet-width);
  margin: 0 auto;
  padding-left: var(--sheet-side-padding);
  padding-right: var(--sheet-side-padding);
  color: var(--sheet-text);
  background: transparent;
}

.rule-sheet__content {
  min-height: 180px;
  font-size: var(--content-font-size);
  line-height: var(--content-line-height);
}

.rule-sheet__content.empty {
  display: grid;
  place-items: center;
  min-height: 220px;
  border: 2px dashed rgba(148, 163, 184, 0.45);
  border-radius: 20px;
  color: #64748b;
  background: rgba(255, 255, 255, 0.64);
}

.rule-sheet__content > :first-child {
  margin-top: 0;
}

.rule-sheet__content > :last-child {
  margin-bottom: 0;
}

.rule-sheet__content p,
.rule-sheet__content ul,
.rule-sheet__content ol,
.rule-sheet__content hr,
.rule-sheet__content table,
.rule-sheet__content h1,
.rule-sheet__content h2,
.rule-sheet__content h3,
.rule-sheet__content h4,
.rule-sheet__content .table-editor-shell {
  margin: 0 0 var(--content-spacing);
}

.rule-sheet__content h1,
.rule-sheet__content h2,
.rule-sheet__content h3,
.rule-sheet__content h4 {
  font-size: calc(var(--content-font-size) * 1.25);
  line-height: 1.45;
  font-weight: 700;
}

.rule-sheet__content ul,
.rule-sheet__content ol {
  padding-left: var(--content-spacing);
}

.rule-sheet__content li + li {
  margin-top: var(--list-item-spacing);
}

.rule-sheet.is-exporting .rule-sheet__content ol,
.rule-sheet.is-exporting .rule-sheet__content ul {
  list-style-position: outside;
  padding-left: calc(var(--content-font-size) * 1.6);
}

.rule-sheet__content strong {
  font-weight: 800;
}

.rule-sheet__content img {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
  margin: 0;
  border-radius: 14px;
}

.rule-sheet__content table img,
.table-editor-cell-inner img {
  width: auto;
  max-width: 100%;
  height: auto;
  border-radius: 0;
}

.rule-sheet__content hr {
  border: 0;
  height: 1px;
  background: color-mix(in srgb, var(--sheet-text) 22%, transparent);
}

.rule-sheet__content table {
  width: 100%;
  border-collapse: collapse;
  table-layout: fixed;
  border: 2px solid var(--table-border);
}

.rule-sheet__content th,
.rule-sheet__content td {
  padding: 8px 4px;
  text-align: var(--table-text-align);
  vertical-align: middle;
  border: 1px solid var(--table-border);
  background: var(--body-cell-fill);
  color: var(--body-cell-text);
  font-size: var(--table-font-size);
  font-weight: 500;
  line-height: 1.5;
  white-space: normal;
  word-break: break-word;
}

.rule-sheet[data-header-column="true"] .rule-sheet__content table tbody tr > :first-child,
.rule-sheet[data-header-column="true"][data-header-row="false"] .rule-sheet__content table thead tr > :first-child {
  background: var(--first-column-fill);
  color: var(--first-column-text);
  font-weight: 700;
}

.rule-sheet[data-header-row="true"] .rule-sheet__content table thead th {
  background: var(--header-row-fill);
  color: var(--header-row-text);
  font-weight: 700;
}

.rule-sheet[data-header-row="false"] .rule-sheet__content table thead th {
  background: var(--body-cell-fill);
  color: var(--body-cell-text);
  font-weight: 500;
}

.table-editor-shell {
  position: relative;
  width: max-content;
  max-width: none;
  min-height: 36px;
}

.table-editor-column-resizer,
.table-editor-row-resizer {
  position: absolute;
  background: transparent;
  z-index: 4;
  pointer-events: auto;
}

.table-editor-column-resizer {
  top: 0;
  width: 12px;
  height: 100%;
  cursor: col-resize;
  transform: translateX(-50%);
}

.table-editor-row-resizer {
  left: 0;
  width: 100%;
  height: 12px;
  cursor: row-resize;
  transform: translateY(-50%);
}

.table-editor-column-resizer::after,
.table-editor-row-resizer::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 999px;
  background: transparent;
  opacity: 0;
  transition: opacity 120ms ease;
}

.table-editor-column-resizer::after {
  left: 5px;
  width: 2px;
}

.table-editor-row-resizer::after {
  top: 5px;
  height: 2px;
}

.table-editor-column-resizer:hover::after,
.table-editor-row-resizer:hover::after,
.table-editor-column-resizer.is-active::after,
.table-editor-row-resizer.is-active::after {
  background: rgba(11, 118, 200, 0.45);
  opacity: 1;
}

.table-editor-table-wrap {
  position: relative;
  overflow: visible;
}

.table-editor-column-handles,
.table-editor-row-handles {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.table-editor-table {
  width: auto;
  border-collapse: collapse;
  table-layout: fixed;
  border: 2px solid var(--table-border);
  font-size: var(--table-font-size);
  line-height: 1.5;
}

.table-editor-cell {
  position: relative;
  padding: 0;
  border: 1px solid var(--table-border);
  vertical-align: middle;
  transition: box-shadow 120ms ease, background 120ms ease;
}

.table-editor-cell.is-row-selected,
.table-editor-cell.is-column-selected {
  box-shadow: inset 0 0 0 999px var(--selection-fill);
}

.table-editor-cell.is-selected {
  box-shadow: inset 0 0 0 2px var(--selection-outline);
  z-index: 1;
}

.table-editor-cell-inner {
  display: flex;
  align-items: center;
  min-height: 100%;
  width: 100%;
  padding: 8px 4px;
  background: transparent;
  white-space: pre-wrap;
  word-break: break-word;
}

.table-editor-cell.is-title-column .table-editor-cell-inner,
.table-editor-cell.is-header-row .table-editor-cell-inner {
  font-weight: 700;
}

.table-editor-cell.is-editing {
  box-shadow: inset 0 0 0 2px var(--selection-outline);
}

.table-editor-input {
  width: 100%;
  min-height: calc(100% - 10px);
  border: none;
  resize: none;
  background: transparent;
  color: inherit;
  font: inherit;
  line-height: inherit;
  padding: 8px 4px;
  outline: none;
}

.rule-sheet.is-exporting .table-editor-cell.is-row-selected,
.rule-sheet.is-exporting .table-editor-cell.is-column-selected,
.rule-sheet.is-exporting .table-editor-cell.is-selected,
.rule-sheet.is-exporting .table-editor-cell.is-editing {
  box-shadow: none;
}

body.is-resizing,
body.is-resizing * {
  cursor: col-resize;
  user-select: none;
}

body.is-resizing.row-resize,
body.is-resizing.row-resize * {
  cursor: row-resize;
}

@media (max-width: 960px) {
  .preview-stage {
    padding: 14px;
  }
}

@media (max-width: 640px) {
  .preview-shell {
    padding: 10px;
  }

  .preview-stage {
    padding: 10px;
  }

  .align-group {
    grid-template-columns: 1fr;
  }
}
