:root {
  --bg: #ffffff;
  --ink: #203040;
  --line: #a6b2bf;
  --major: #2d3f51;
  --pink: #ffd6e6;
  --blue: #d7efff;
  --gray: #ececec;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Yu Gothic UI", "Meiryo", sans-serif;
  color: var(--ink);
  background: var(--bg);
}

main {
  overflow-x: hidden;
}

.topbar {
  position: sticky;
  top: 0;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #ffffffdd;
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
  z-index: 20;
}

.actions {
  display: flex;
  gap: 8px;
}

.print-meta {
  display: none;
}

button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 6px;
  padding: 6px 12px;
  cursor: pointer;
}

.boards {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px;
}

.board {
  background: #fff;
  border: 0;
  border-radius: 0;
  padding: 6px;
}

.board-row {
  --side-width: 28px;
  --row-gap: 8px;
  --betcho-gap: 10px;
  --betcho-right-space: 16px;
  --inner-width: calc(100% - var(--side-width) - (2 * var(--row-gap)));
  --one-page-width: calc((var(--inner-width) - var(--betcho-gap) - var(--betcho-right-space)) / 17);
  --betcho-reserve: calc(var(--one-page-width) + var(--betcho-gap) + var(--betcho-right-space));
  position: relative;
  display: grid;
  grid-template-columns: var(--side-width) minmax(0, 1fr) var(--betcho-reserve);
  column-gap: var(--row-gap);
  align-items: flex-start;
  overflow: hidden;
}

.board-row .board-side {
  grid-column: 1;
}

.board-row .page-track {
  grid-column: 2;
  width: 100%;
}

.betcho-list {
  grid-column: 3;
  width: 100%;
  padding-left: var(--betcho-gap);
  padding-right: var(--betcho-right-space);
  box-sizing: border-box;
  display: flex;
  flex-direction: column;
  gap: 6px;
  overflow: visible;
  pointer-events: auto;
}

.betcho-item {
  min-height: 56px;
  width: 100%;
  border: 1px solid var(--line);
  background: #fff;
  padding: 4px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  pointer-events: auto;
}

.betcho-name {
  font-size: 10px;
  line-height: 1.3;
  font-weight: 600;
  word-break: break-all;
}

.betcho-advance {
  margin-top: 2px;
  font-size: 9px;
  color: #455a6f;
}

.board-side {
  width: 28px;
  flex: 0 0 28px;
}

.board-no,
.board-format {
  border: 1px solid var(--line);
  text-align: center;
  font-size: 10px;
  line-height: 1.2;
  padding: 3px 0;
}

.board-format {
  margin-top: 4px;
}

.page-track {
  display: grid;
  grid-template-columns: repeat(16, minmax(0, 1fr));
  gap: 0;
  width: 100%;
}

.page-slot {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.page-cell {
  min-height: 56px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  border-left: 0;
  border-right: 0;
  padding: 0;
  overflow: hidden;
  user-select: none;
  background: #fff;
  display: flex;
  flex-direction: column;
}

.page-number {
  min-height: 14px;
  font-size: 10px;
  color: #28333f;
  text-align: center;
  padding-top: 1px;
}

.cell-row {
  min-height: 0;
  padding: 1px 3px;
  overflow: hidden;
  border-right: 1px solid var(--line);
}

.row-large {
  flex: 0 0 22px;
  background: #fff;
  border-bottom: 1px solid #9eabb7;
}

.row-middle {
  flex: 0 0 16px;
  background: #fff;
}

.row-small {
  flex: 0 0 16px;
  background: #fff;
}

.segment {
  display: block;
  max-width: 100%;
  font-size: 10px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  padding: 0;
  margin: 0;
  line-height: 1.25;
  background: transparent;
  border-radius: 0;
}

.seg-large {
  font-weight: 500;
}

.seg-middle {
  font-weight: 400;
}

.seg-small {
  font-size: 9px;
}

.left-thick {
  border-left: 2px solid #99a8b3;
}

.sep-none {
  border-right: 0 !important;
}

.sep-solid {
  border-right: 1px solid #9eabb7;
}

.sep-dotted {
  border-right: 2px dotted #9eabb7;
}

.sep-thick {
  border-right: 2px solid #9eabb7;
}

.is-over {
  background: var(--pink);
}

.is-under {
  background: var(--blue);
}

.band-over {
  background: var(--pink);
}

.band-under {
  background: var(--blue);
}

.row-middle.band-over {
  background: var(--pink);
}

.row-small.band-over {
  background: #fff;
}

.is-anon {
  background: var(--gray);
  color: #687480;
}

.tooltip {
  position: fixed;
  z-index: 50;
  max-width: 320px;
  font-size: 12px;
  background: #2f3e4dbf;
  color: #fff;
  padding: 8px;
  border-radius: 6px;
  line-height: 1.4;
}

.hidden {
  display: none;
}

dialog {
  width: min(1000px, 94vw);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 12px;
}

dialog::backdrop {
  background: #0f1f3040;
}

.help-body {
  font-size: 13px;
  line-height: 1.45;
}

.help-body h4 {
  margin: 10px 0 4px;
  font-size: 13px;
}

.help-body p {
  margin: 0 0 6px;
}

#editorDialog .editor-text-wrap {
  position: relative;
}

#editorText {
  width: 100%;
  height: min(70vh, 700px);
  font-family: ui-monospace, "Cascadia Code", monospace;
}

.editor-assist {
  margin-top: 6px;
}

.editor-help {
  font-size: 11px;
  color: #5c6976;
  line-height: 1.3;
}

.editor-help code {
  font-family: ui-monospace, "Cascadia Code", monospace;
}

.editor-candidate {
  position: absolute;
  left: 0;
  top: 0;
  color: #0d5cff;
  font-size: 14px;
  font-family: ui-monospace, "Cascadia Code", monospace;
  white-space: pre;
  pointer-events: none;
  min-height: 0;
  z-index: 2;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.article-list table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.article-list th,
.article-list td {
  border: 1px solid var(--line);
  padding: 4px;
}

@media print {
  @page {
    size: A4 portrait;
    margin: 10mm;
  }

  html,
  body {
    width: 210mm;
    background: #fff;
  }

  .topbar,
  #editorDialog,
  #articleDialog,
  #helpDialog,
  #articleDialog .dialog-actions {
    display: none;
  }

  .boards {
    gap: 3mm;
    padding: 0;
  }

  .print-meta {
    display: block;
    margin: 0 0 3mm;
    padding-bottom: 1.5mm;
    border-bottom: 0.3mm solid #8f9eaa;
    font-size: 10.5pt;
    font-weight: 600;
    line-height: 1.3;
    color: #1f2f40;
  }

  .board {
    width: 100%;
    margin: 0;
    padding: 2mm;
    border: 0;
    border-radius: 0;
    break-inside: avoid;
    page-break-inside: avoid;
  }

  .page-cell,
  .row-large,
  .row-middle,
  .row-small,
  .segment,
  .betcho-item {
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
}
