:root {
  --button-top: #d6dce4;
  --button-mid: #aeb8c6;
  --button-bottom: #778292;
  --button-border-dark: #323947;
  --button-border-light: #f9fbff;
  --text: #203247;
  --panel: rgba(248, 252, 255, 0.9);
  --line: rgba(84, 113, 143, 0.28);
}

* {
  box-sizing: border-box;
}

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

body {
  font-family: "Yu Gothic", "Meiryo", "Hiragino Kaku Gothic ProN", sans-serif;
  color: var(--text);
  background: #eef6ff;
}

.screen {
  position: relative;
  display: none;
  grid-template-rows: minmax(120px, 26vh) auto 1fr;
  min-height: 100vh;
  padding: 28px 18px;
  overflow: hidden;
  background:
    linear-gradient(rgba(255, 255, 255, 0.16), rgba(225, 241, 255, 0.28)),
    url("assets/logic-bg.png") center / cover no-repeat;
}

.screen.active {
  display: grid;
}

.screen::after {
  position: absolute;
  inset: 0;
  pointer-events: none;
  content: "";
  background:
    radial-gradient(circle at center 18%, rgba(255, 255, 255, 0.78), transparent 34%),
    linear-gradient(180deg, transparent 62%, rgba(222, 239, 255, 0.35));
}

.logo,
.menu,
.page-header,
.library-panel,
.play-layout {
  position: relative;
  z-index: 1;
}

.logo {
  align-self: end;
  max-width: calc(100vw - 36px);
  margin: 0 auto;
  text-align: center;
  font-size: clamp(42px, 7vw, 96px);
  font-weight: 900;
  line-height: 0.95;
  letter-spacing: 0;
  color: #f7fbff;
  -webkit-text-stroke: clamp(2px, 0.45vw, 6px) #566d89;
  text-shadow:
    0 5px 0 #8fa4bd,
    0 10px 0 #576c85,
    0 16px 22px rgba(67, 105, 145, 0.28);
}

.menu {
  display: grid;
  gap: 10px;
  width: min(520px, calc(100vw - 32px));
  margin: 44px auto 0;
}

.menu button {
  min-height: 48px;
  padding: 9px 18px 10px;
  border: 2px solid var(--button-border-dark);
  border-top-color: var(--button-border-light);
  border-left-color: var(--button-border-light);
  border-radius: 0;
  color: #243348;
  font: 700 18px/1.2 "Yu Gothic", "Meiryo", sans-serif;
  letter-spacing: 0;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.72);
  cursor: pointer;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), transparent 44%),
    linear-gradient(180deg, var(--button-top), var(--button-mid) 48%, var(--button-bottom));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.42),
    0 3px 0 rgba(61, 73, 91, 0.82),
    0 8px 18px rgba(101, 139, 176, 0.22);
}

.menu button:hover,
.menu button:focus-visible {
  color: #143a66;
  outline: 3px solid rgba(117, 174, 235, 0.42);
  outline-offset: 2px;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.32), transparent 42%),
    linear-gradient(180deg, #e3eaf1, #b9c5d2 48%, #8391a3);
}

.menu button:active {
  transform: translateY(2px);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.34),
    0 1px 0 rgba(61, 73, 91, 0.82),
    0 4px 12px rgba(101, 139, 176, 0.2);
}

.library-view,
.single-view,
.play-view {
  grid-template-rows: auto 1fr;
  gap: 24px;
  overflow: auto;
}

.page-header {
  display: grid;
  grid-template-columns: 112px 1fr 112px;
  align-items: center;
  gap: 12px;
  width: min(1100px, calc(100vw - 32px));
  margin: 0 auto;
}

.page-header h1 {
  margin: 0;
  text-align: center;
  font-size: clamp(34px, 5vw, 64px);
  font-weight: 900;
  line-height: 1;
  color: #f7fbff;
  -webkit-text-stroke: 3px #566d89;
  text-shadow:
    0 4px 0 #8fa4bd,
    0 8px 0 #576c85,
    0 12px 18px rgba(67, 105, 145, 0.26);
}

.pixel-button {
  min-height: 42px;
  padding: 8px 14px;
  border: 2px solid var(--button-border-dark);
  border-top-color: var(--button-border-light);
  border-left-color: var(--button-border-light);
  border-radius: 0;
  color: #243348;
  font: 700 15px/1.2 "Yu Gothic", "Meiryo", sans-serif;
  text-align: center;
  text-decoration: none;
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.72);
  cursor: pointer;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.24), transparent 44%),
    linear-gradient(180deg, var(--button-top), var(--button-mid) 48%, var(--button-bottom));
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.42),
    0 3px 0 rgba(61, 73, 91, 0.82);
}

.pixel-button.primary {
  color: #153452;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.28), transparent 44%),
    linear-gradient(180deg, #dff2ff, #9fc9ec 48%, #5f92c4);
}

.pixel-button:disabled {
  color: #69798a;
  cursor: not-allowed;
  filter: grayscale(0.35);
  opacity: 0.62;
}

.pixel-button.small {
  min-height: 38px;
  padding-inline: 10px;
}

.library-panel {
  width: min(1100px, calc(100vw - 32px));
  min-height: 55vh;
  margin: 0 auto;
  padding: 18px;
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 16px 36px rgba(91, 130, 171, 0.18);
}

.section-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  padding-bottom: 14px;
  border-bottom: 1px solid var(--line);
}

.compact-title {
  padding-bottom: 8px;
}

.compact-title h2 {
  font-size: 16px;
}

.section-title h2 {
  margin: 0;
  font-size: 22px;
  line-height: 1.25;
}

.section-title span {
  flex: 0 0 auto;
  font-weight: 700;
  color: #527092;
}

.logic-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  margin-top: 16px;
}

.logic-card {
  position: relative;
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.86);
}

.card-image-wrap {
  position: relative;
}

.logic-card img {
  width: 100%;
  aspect-ratio: 4 / 3;
  object-fit: cover;
  border: 1px solid rgba(83, 112, 142, 0.22);
  background: #eaf3fc;
}

.card-progress-mini {
  position: absolute;
  left: var(--card-mini-left, 7px);
  top: var(--card-mini-top, 7px);
  display: grid;
  width: var(--card-mini-width, min(42%, 130px));
  height: var(--card-mini-height, auto);
  max-height: var(--card-mini-max-height, 42%);
  aspect-ratio: var(--card-mini-cols, 1) / var(--card-mini-rows, 1);
  overflow: hidden;
  border: var(--card-mini-border, 2px solid rgba(255, 255, 255, 0.95));
  background: var(--card-mini-background, rgba(255, 255, 255, 0.36));
  box-shadow: var(--card-mini-shadow, 0 4px 12px rgba(21, 42, 64, 0.24));
  pointer-events: none;
}

.card-progress-mini:empty {
  display: none;
}

.card-progress-mini i {
  background: rgba(32, 50, 71, 0.9);
}

.favorite-button,
.kebab-button {
  position: absolute;
  top: 7px;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid rgba(76, 99, 125, 0.55);
  color: #243348;
  font: 900 20px/1 sans-serif;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.9);
}

.favorite-button {
  left: 7px;
}

.favorite-button.active {
  color: #be8a00;
}

.kebab-button {
  right: 7px;
}

.card-play-button {
  position: absolute;
  right: 7px;
  bottom: 7px;
  min-width: 72px;
}

.card-menu-wrap {
  position: absolute;
  top: 7px;
  right: 7px;
}

.card-menu {
  position: absolute;
  top: 39px;
  right: 0;
  display: grid;
  min-width: 180px;
  padding: 5px;
  border: 1px solid rgba(76, 99, 125, 0.55);
  background: rgba(255, 255, 255, 0.98);
  box-shadow: 0 10px 20px rgba(42, 64, 88, 0.18);
  z-index: 4;
}

.card-menu[hidden] {
  display: none;
}

.card-menu button {
  min-height: 36px;
  border: 0;
  color: #203247;
  font: 700 13px/1.2 "Yu Gothic", "Meiryo", sans-serif;
  text-align: left;
  cursor: pointer;
  background: transparent;
}

.card-menu button:hover,
.card-menu button:focus-visible {
  background: #e9f4ff;
}

.logic-info {
  display: grid;
  gap: 4px;
}

.logic-info strong {
  font-size: 16px;
}

.logic-info span,
.logic-info time {
  color: #52677f;
  font-size: 13px;
}

.status-row,
.filter-bar,
.type-tabs,
.grid-size-fields {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.status-pill,
.size-pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 3px 8px;
  border: 1px solid rgba(82, 103, 127, 0.24);
  color: #39516c;
  font-size: 12px;
  font-weight: 800;
  background: #edf5fd;
}

.status-pill[data-status="playing"] {
  color: #7c5700;
  background: #fff3cf;
}

.status-pill[data-status="cleared"] {
  color: #1f6b48;
  background: #dcf5e8;
}

.filter-bar {
  margin-top: 14px;
}

.filter-bar select,
.filter-bar input,
.field select {
  min-height: 38px;
  padding: 7px 10px;
  border: 1px solid rgba(76, 99, 125, 0.58);
  color: #203247;
  font: 700 14px/1.2 "Yu Gothic", "Meiryo", sans-serif;
  background: rgba(255, 255, 255, 0.94);
}

.filter-bar input {
  width: 92px;
}

.type-tabs {
  margin-top: 16px;
}

.empty-message {
  margin: 34px 0 0;
  text-align: center;
  color: #52677f;
  font-weight: 700;
}

.register-dialog {
  width: min(980px, calc(100vw - 24px));
  max-height: min(760px, calc(100vh - 24px));
  padding: 0;
  border: 1px solid rgba(62, 82, 105, 0.62);
  background: transparent;
}

.register-dialog::backdrop {
  background: rgba(28, 48, 72, 0.46);
}

.dialog-card {
  display: grid;
  gap: 16px;
  max-height: inherit;
  padding: 18px;
  overflow: auto;
  background:
    linear-gradient(rgba(255, 255, 255, 0.88), rgba(238, 247, 255, 0.94)),
    url("assets/logic-bg.png") center / cover no-repeat;
}

.dialog-head,
.dialog-actions,
.camera-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.dialog-head {
  justify-content: space-between;
}

.dialog-head h2 {
  margin: 0;
  font-size: 24px;
}

.icon-close {
  display: grid;
  place-items: center;
  width: 36px;
  height: 36px;
  border: 1px solid rgba(76, 99, 125, 0.55);
  color: #243348;
  font: 900 24px/1 sans-serif;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.78);
}

.type-choices {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.choice {
  min-height: 58px;
  padding: 9px 10px;
  border: 2px solid rgba(76, 99, 125, 0.72);
  color: #243348;
  font: 800 15px/1.25 "Yu Gothic", "Meiryo", sans-serif;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.78);
}

.choice.selected {
  border-color: #3d78b8;
  color: #113a62;
  background: #dff1ff;
  box-shadow: inset 0 0 0 2px rgba(255, 255, 255, 0.75);
}

.field {
  display: grid;
  gap: 6px;
  font-weight: 700;
}

.field input,
.field textarea,
.field select {
  min-height: 42px;
  padding: 8px 10px;
  border: 1px solid rgba(76, 99, 125, 0.58);
  color: #203247;
  font: 16px/1.3 "Yu Gothic", "Meiryo", sans-serif;
  background: rgba(255, 255, 255, 0.9);
}

.field textarea {
  min-height: 86px;
  resize: vertical;
}

.issue-fields {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr minmax(180px, 1.6fr);
  gap: 10px;
  align-items: end;
}

.year-input-wrap {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 6px;
  min-height: 42px;
  padding-inline: 10px;
  border: 1px solid rgba(76, 99, 125, 0.58);
  background: rgba(255, 255, 255, 0.9);
}

.year-input-wrap input {
  min-height: 30px;
  padding: 3px 4px;
  border: 0;
  text-align: center;
  background: transparent;
}

.year-input-wrap span,
.year-input-wrap small {
  color: #52677f;
  font-weight: 900;
}

.generated-title input {
  background: rgba(232, 242, 252, 0.92);
}

.legacy-ocr {
  display: none !important;
}

.hint-register-panel {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.68);
}

.hint-image-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}

.hint-image-panel {
  display: grid;
  gap: 10px;
  min-width: 0;
  padding: 10px;
  border: 1px solid rgba(76, 99, 125, 0.22);
  background: rgba(255, 255, 255, 0.72);
}

.hint-panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.hint-panel-head strong {
  color: #39516c;
}

.hint-adjuster {
  display: grid;
  gap: 10px;
}

.hint-adjuster[hidden] {
  display: none;
}

.hint-stage {
  position: relative;
  overflow: hidden;
  min-height: 0;
  border: 1px solid rgba(76, 99, 125, 0.32);
  background: #edf5fc;
  touch-action: none;
}

.hint-stage img {
  display: block;
  width: 100%;
  height: auto;
}

.hint-guide-lines,
.hint-crop-box {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.hint-guide-lines i {
  position: absolute;
  display: block;
  height: 2px;
  transform-origin: 0 50%;
  background: rgba(32, 92, 150, 0.72);
}

.hint-guide-lines i.vertical {
  height: 2px;
}

.hint-guide-lines i.horizontal {
  height: 2px;
}

.hint-guide-arrow {
  position: absolute;
  z-index: 4;
  display: grid;
  place-items: center;
  width: 28px;
  height: 28px;
  padding: 0;
  border: 2px solid rgba(255, 255, 255, 0.96);
  border-radius: 50%;
  color: #ffffff;
  font: 900 18px/1 sans-serif;
  cursor: grab;
  transform: translate(-50%, -50%);
  background: rgba(230, 41, 41, 0.88);
  box-shadow: 0 2px 10px rgba(17, 38, 60, 0.28);
  pointer-events: auto;
  touch-action: none;
}

.hint-guide-arrow.dragging {
  z-index: 9;
  width: 40px;
  height: 40px;
  background: rgba(199, 28, 28, 0.94);
}

.hint-crop-box {
  background: rgba(46, 139, 87, 0.08);
  box-shadow:
    0 0 0 9999px rgba(15, 31, 49, 0.22),
    inset 0 0 0 1px rgba(255, 255, 255, 0.78);
}

.hint-corner {
  position: absolute;
  z-index: 3;
  width: 38px;
  height: 38px;
  padding: 0;
  border: 4px solid #ffffff;
  border-radius: 50%;
  cursor: grab;
  transform: translate(-50%, -50%);
  background: rgba(46, 139, 87, 0.2);
  box-shadow:
    0 2px 12px rgba(31, 69, 106, 0.42),
    inset 0 0 0 2px rgba(255, 255, 255, 0.38);
  touch-action: none;
  transition:
    width 120ms ease,
    height 120ms ease,
    background-color 120ms ease,
    box-shadow 120ms ease;
}

.hint-corner::after {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 15px;
  border-radius: 99px;
  background: #e62929;
  pointer-events: none;
  transform: translateX(-50%);
}

.hint-corner::before {
  content: "";
  position: absolute;
  left: 50%;
  top: 50%;
  width: 15px;
  height: 3px;
  border-radius: 99px;
  background: #e62929;
  pointer-events: none;
  transform: translateY(-50%);
}

.hint-corner[data-hint-corner$="-tr"]::before,
.hint-corner[data-hint-corner$="-br"]::before {
  transform: translate(-100%, -50%);
}

.hint-corner[data-hint-corner$="-br"]::after,
.hint-corner[data-hint-corner$="-bl"]::after {
  transform: translate(-50%, -100%);
}

.hint-corner.selected {
  z-index: 5;
  width: 48px;
  height: 48px;
  border-color: rgba(255, 255, 255, 0.98);
  background: rgba(230, 41, 41, 0.16);
  box-shadow:
    0 4px 18px rgba(31, 69, 106, 0.5),
    0 0 0 4px rgba(255, 255, 255, 0.26),
    inset 0 0 0 2px rgba(255, 255, 255, 0.36);
}

.hint-corner.dragging {
  z-index: 8;
  width: 68px;
  height: 68px;
  border-color: rgba(255, 255, 255, 1);
  background: rgba(230, 41, 41, 0.12);
  box-shadow:
    0 8px 26px rgba(18, 42, 66, 0.58),
    0 0 0 5px rgba(255, 255, 255, 0.34),
    inset 0 0 0 3px rgba(255, 255, 255, 0.42);
}

.hint-corner:active {
  cursor: grabbing;
}

.hint-loupe {
  position: absolute;
  z-index: 7;
  width: 168px;
  height: 168px;
  overflow: hidden;
  border: 4px solid rgba(255, 255, 255, 0.96);
  border-radius: 50%;
  background: #ffffff;
  box-shadow:
    0 10px 28px rgba(13, 28, 46, 0.42),
    0 0 0 1px rgba(32, 63, 94, 0.28);
  pointer-events: none;
}

.hint-loupe[hidden] {
  display: none;
}

.hint-loupe img {
  position: absolute;
  z-index: 1;
  display: block;
  max-width: none;
  width: auto;
  height: auto;
  pointer-events: none;
}

.hint-loupe::after {
  content: "";
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  width: 3px;
  height: 42px;
  border-radius: 99px;
  background: #e62929;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.82);
  transform: translateX(-50%);
}

.hint-loupe::before {
  content: "";
  position: absolute;
  z-index: 2;
  left: 50%;
  top: 50%;
  width: 42px;
  height: 3px;
  border-radius: 99px;
  background: #e62929;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.82);
  transform: translateY(-50%);
}

.hint-loupe.corner-tr::before,
.hint-loupe.corner-br::before {
  transform: translate(-100%, -50%);
}

.hint-loupe.corner-br::after,
.hint-loupe.corner-bl::after {
  transform: translate(-50%, -100%);
}

.hint-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px 12px;
}

.hint-controls label {
  display: grid;
  gap: 4px;
  color: #52677f;
  font-size: 12px;
  font-weight: 900;
}

.register-size-fields {
  align-items: stretch;
}

.register-preview {
  display: grid;
  gap: 10px;
  padding: 10px;
  border: 1px solid rgba(76, 99, 125, 0.22);
  background: rgba(255, 255, 255, 0.76);
}

.register-preview[hidden] {
  display: none;
}

.preview-board-scroll {
  overflow: auto;
  max-height: 430px;
  border: 1px solid rgba(82, 103, 127, 0.28);
  background: #d8e6f2;
}

.preview-board {
  display: grid;
  width: max-content;
  min-width: 100%;
  --preview-cell-size: 20px;
  --preview-top-height: 120px;
  --preview-left-width: 120px;
  background: #9eb5ce;
}

.preview-board .preview-corner,
.preview-board .preview-top-image,
.preview-board .preview-left-image,
.preview-board .preview-cell {
  border-right: 1px solid #9eb5ce;
  border-bottom: 1px solid #9eb5ce;
  background: #ffffff;
}

.preview-board .preview-corner {
  width: var(--preview-left-width);
  height: var(--preview-top-height);
  background: #dcecf9;
}

.preview-board .preview-top-image,
.preview-board .preview-left-image {
  overflow: hidden;
  background: #f8fbff;
}

.preview-board img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.preview-board .preview-cell {
  width: var(--preview-cell-size);
  height: var(--preview-cell-size);
}

.camera-box {
  display: grid;
  place-items: center;
  min-height: 260px;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.74);
}

.camera-box video,
.camera-box img {
  width: 100%;
  max-height: 420px;
  object-fit: contain;
}

.camera-box p {
  margin: 0;
  color: #52677f;
  font-weight: 700;
  text-align: center;
}

.camera-actions,
.dialog-actions {
  justify-content: flex-end;
  flex-wrap: wrap;
}

.ocr-fields {
  display: grid;
  gap: 12px;
}

.ocr-range-panel {
  display: grid;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.66);
}

.ocr-region-editor {
  overflow: auto;
  padding: 8px;
  border: 1px solid rgba(76, 99, 125, 0.24);
  background: rgba(255, 255, 255, 0.7);
}

.ocr-region-editor[hidden] {
  display: none;
}

.ocr-region-stage {
  position: relative;
  width: min(100%, 900px);
  margin: 0 auto;
  touch-action: none;
  user-select: none;
}

.ocr-region-stage img {
  display: block;
  width: 100%;
  height: auto;
  border: 1px solid rgba(76, 99, 125, 0.35);
  background: #ffffff;
}

.ocr-box {
  position: absolute;
  min-width: 34px;
  min-height: 28px;
  border: 3px solid #1e79c7;
  cursor: move;
  background: rgba(30, 121, 199, 0.16);
  box-shadow:
    0 0 0 2px rgba(255, 255, 255, 0.86),
    0 8px 18px rgba(31, 69, 106, 0.18);
}

.ocr-box span {
  position: absolute;
  left: -3px;
  top: -30px;
  min-width: max-content;
  padding: 4px 7px;
  color: #ffffff;
  font-size: 12px;
  font-weight: 900;
  background: #1e79c7;
}

.ocr-box.row-box {
  border-color: #c75b1e;
  background: rgba(199, 91, 30, 0.15);
}

.ocr-box.row-box span {
  background: #c75b1e;
}

.ocr-box i {
  position: absolute;
  right: -9px;
  bottom: -9px;
  width: 18px;
  height: 18px;
  border: 2px solid #ffffff;
  cursor: nwse-resize;
  background: currentColor;
  box-shadow: 0 2px 8px rgba(31, 69, 106, 0.24);
}

.board-corners-svg {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
  z-index: 3;
}

.board-corners-svg polygon {
  fill: rgba(74, 153, 74, 0.12);
  stroke: #2e8b57;
  stroke-width: 3;
  vector-effect: non-scaling-stroke;
}

.board-corner {
  position: absolute;
  z-index: 4;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 3px solid #ffffff;
  border-radius: 50%;
  cursor: grab;
  transform: translate(-50%, -50%);
  background: #2e8b57;
  box-shadow: 0 2px 10px rgba(31, 69, 106, 0.38);
  touch-action: none;
}

.board-corner:active {
  cursor: grabbing;
}

.range-empty {
  margin: 0;
  color: #52677f;
  font-size: 13px;
  font-weight: 700;
}

.range-empty[hidden] {
  display: none;
}

.range-details {
  display: grid;
  gap: 8px;
}

.range-details summary {
  width: fit-content;
  color: #39516c;
  font-size: 13px;
  font-weight: 900;
  cursor: pointer;
}

.range-grid {
  display: grid;
  grid-template-columns: 80px repeat(4, 1fr);
  gap: 8px;
  align-items: end;
}

.range-grid strong {
  color: #39516c;
  font-size: 13px;
}

.range-grid label {
  display: grid;
  gap: 3px;
  color: #52677f;
  font-size: 12px;
  font-weight: 800;
}

.range-grid input {
  min-width: 0;
  min-height: 34px;
  padding: 5px 6px;
  border: 1px solid rgba(76, 99, 125, 0.58);
  color: #203247;
  font: 700 13px/1.2 "Yu Gothic", "Meiryo", sans-serif;
  background: rgba(255, 255, 255, 0.92);
}

.segmented-results {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.7);
}

.segmented-results[hidden] {
  display: none;
}

.result-columns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.result-columns h3 {
  margin: 0 0 8px;
  color: #39516c;
  font-size: 15px;
}

.result-list {
  display: grid;
  gap: 5px;
  max-height: 300px;
  overflow: auto;
  padding-right: 4px;
}

.result-row {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 6px;
  align-items: center;
}

.result-row span {
  color: #52677f;
  font-size: 12px;
  font-weight: 900;
}

.result-row input {
  min-width: 0;
  min-height: 32px;
  padding: 5px 7px;
  border: 1px solid rgba(76, 99, 125, 0.42);
  color: #203247;
  font: 700 13px/1.2 "Yu Gothic", "Meiryo", sans-serif;
  background: rgba(255, 255, 255, 0.96);
}

.grid-size-fields .field {
  flex: 1 1 120px;
}

.property-grid {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 8px 12px;
  padding: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.72);
}

.property-grid span {
  color: #52677f;
  font-weight: 700;
}

.property-grid strong {
  overflow-wrap: anywhere;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(240px, 360px) 1fr;
  gap: 18px;
  width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
}

.source-panel,
.board-panel {
  border: 1px solid var(--line);
  background: var(--panel);
  box-shadow: 0 16px 36px rgba(91, 130, 171, 0.18);
}

.source-panel {
  display: grid;
  align-content: start;
  gap: 12px;
  padding: 12px;
}

.source-image-wrap {
  position: relative;
  display: grid;
  background: #ffffff;
}

.source-panel img {
  width: 100%;
  max-height: 52vh;
  object-fit: contain;
  border: 1px solid rgba(83, 112, 142, 0.22);
  background: #ffffff;
}

.progress-mini {
  position: absolute;
  left: var(--mini-left, 8px);
  top: var(--mini-top, 8px);
  display: grid;
  width: var(--mini-width, min(42%, 150px));
  height: var(--mini-height, auto);
  max-height: var(--mini-max-height, 42%);
  aspect-ratio: var(--mini-cols, 1) / var(--mini-rows, 1);
  overflow: hidden;
  border: var(--mini-border, 2px solid rgba(255, 255, 255, 0.95));
  background: var(--mini-background, rgba(255, 255, 255, 0.42));
  box-shadow: var(--mini-shadow, 0 4px 14px rgba(21, 42, 64, 0.3));
  pointer-events: none;
}

.progress-mini:empty {
  display: none;
}

.progress-mini i {
  background: rgba(32, 50, 71, 0.92);
}

.play-meta {
  display: grid;
  gap: 4px;
  color: #52677f;
  font-weight: 700;
}

.board-panel {
  display: grid;
  align-content: start;
  gap: 14px;
  padding: 14px;
  min-width: 0;
  overflow: hidden;
}

.board-toolbar {
  position: sticky;
  top: 0;
  z-index: 8;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  flex-wrap: wrap;
  padding-bottom: 8px;
  background: rgba(248, 252, 255, 0.94);
  border-bottom: 1px solid var(--line);
}

.board-toolbar span {
  color: #52677f;
  font-size: 13px;
  font-weight: 700;
}

.tool-group {
  display: inline-flex;
  gap: 6px;
  flex-wrap: wrap;
}

.assist-tools {
  flex-basis: 100%;
}

.input-mode-tools {
  flex-basis: 100%;
}

.tool-button.selected,
.pixel-button.selected {
  color: #ffffff;
  text-shadow: 0 1px 0 rgba(0, 0, 0, 0.32);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 44%),
    linear-gradient(180deg, #55728f, #36506e 48%, #203247);
  box-shadow:
    inset 0 0 0 1px rgba(255, 255, 255, 0.28),
    0 2px 0 rgba(28, 43, 60, 0.86);
}

.pixel-button.soft-disabled {
  opacity: 0.72;
}

.zoom-control {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 38px;
  padding: 6px 10px;
  border: 1px solid rgba(76, 99, 125, 0.35);
  color: #39516c;
  font-size: 13px;
  font-weight: 800;
  background: rgba(255, 255, 255, 0.82);
}

.zoom-control input {
  width: 110px;
}

.board-scroll {
  width: 100%;
  max-height: min(68vh, 760px);
  overflow: auto;
  overscroll-behavior: contain;
  border: 1px solid rgba(82, 103, 127, 0.28);
  background: #d8e6f2;
  -webkit-overflow-scrolling: touch;
}

.logic-board {
  display: grid;
  width: max-content;
  min-width: 100%;
  --cell-size: 30px;
  --top-hint-height: 72px;
  --left-hint-width: 92px;
  background: #9eb5ce;
}

.image-hint-cell {
  overflow: hidden;
  width: auto;
  height: auto;
  padding: 0;
  background: #f8fbff;
}

.image-hint-cell img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: fill;
}

.board-cell {
  position: relative;
  box-sizing: border-box;
  width: var(--cell-size);
  height: var(--cell-size);
  border: 0;
  border-right: 1px solid #9eb5ce;
  border-bottom: 1px solid #9eb5ce;
  color: #35536f;
  font: 900 calc(var(--cell-size) * 0.58) / 1 sans-serif;
  cursor: pointer;
  background: #ffffff;
}

.board-cell.thick-right {
  border-right-width: 3px;
  border-right-color: #607d9a;
}

.board-cell.thick-bottom {
  border-bottom-width: 3px;
  border-bottom-color: #607d9a;
}

.board-cell[data-mark="paint"] {
  background: #203247;
}

.board-cell[data-mark="cross"] {
  background: #eff6fc;
}

.logic-board.show-empty-flash .board-cell[data-mark=""] {
  animation: emptyCellPulse 2s ease-in-out infinite;
}

.run-count-label {
  z-index: 3;
  align-self: center;
  justify-self: center;
  display: grid;
  min-width: calc(var(--cell-size) * 0.74);
  min-height: calc(var(--cell-size) * 0.74);
  padding: 0 4px;
  place-items: center;
  border: 1px solid rgba(255, 255, 255, 0.28);
  color: #ffffff;
  font: 900 calc(var(--cell-size) * 0.48) / 1 sans-serif;
  background: rgba(32, 50, 71, 0.84);
  box-shadow: 0 2px 8px rgba(17, 38, 60, 0.18);
  pointer-events: none;
}

.run-count-label.horizontal {
}

@keyframes emptyCellPulse {
  0%,
  100% {
    background: #ffffff;
  }

  50% {
    background: rgba(231, 77, 77, 0.28);
  }
}

.hint-cell {
  display: flex;
  border-right: 1px solid #9eb5ce;
  border-bottom: 1px solid #9eb5ce;
  color: #243348;
  font-weight: 900;
  background: #f4f9ff;
}

.corner-cell {
  position: sticky;
  top: 0;
  left: 0;
  z-index: 6;
  width: var(--left-hint-width);
  height: var(--top-hint-height);
  background: #dcecf9;
}

.top-hint-cell {
  position: sticky;
  top: 0;
  z-index: 5;
  align-items: flex-end;
  justify-content: flex-end;
  width: var(--cell-size);
  height: var(--top-hint-height);
  padding: 4px 2px;
  flex-direction: column;
  font-size: 12px;
  line-height: 1.05;
}

.left-hint-cell {
  position: sticky;
  left: 0;
  z-index: 4;
  align-items: center;
  justify-content: flex-end;
  width: var(--left-hint-width);
  height: var(--cell-size);
  gap: 4px;
  padding: 2px 7px;
  font-size: 13px;
  white-space: nowrap;
  background: #f4f9ff;
}

.top-hint-cell span,
.left-hint-cell span {
  display: inline-block;
}

.logic-board .top-hint-cell.image-hint-cell {
  width: auto;
  height: var(--top-hint-height);
  align-items: stretch;
  justify-content: stretch;
  flex-direction: row;
  padding: 0;
}

.logic-board .left-hint-cell.image-hint-cell {
  width: var(--left-hint-width);
  height: auto;
  align-items: stretch;
  justify-content: stretch;
  gap: 0;
  padding: 0;
  white-space: normal;
}

.file-button {
  display: inline-grid;
  place-items: center;
}

.file-button input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

@media (max-width: 560px) {
  .screen {
    grid-template-rows: minmax(96px, 22vh) auto 1fr;
    padding-top: 22px;
  }

  .menu {
    gap: 9px;
    margin-top: 34px;
  }

  .menu button {
    min-height: 46px;
    font-size: 16px;
  }

  .library-view {
    grid-template-rows: auto 1fr;
  }

  .page-header {
    grid-template-columns: 76px 1fr 76px;
    width: calc(100vw - 20px);
    gap: 8px;
  }

  .page-header h1 {
    font-size: 36px;
    -webkit-text-stroke-width: 2px;
  }

  .pixel-button.small {
    min-height: 36px;
    padding-inline: 6px;
    font-size: 13px;
  }

  .library-panel {
    width: calc(100vw - 20px);
    padding: 12px;
  }

  .section-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .section-title h2 {
    font-size: 19px;
  }

  .type-choices {
    grid-template-columns: 1fr;
  }

  .issue-fields,
  .hint-image-grid {
    grid-template-columns: 1fr;
  }

  .type-tabs {
    display: grid;
    grid-template-columns: 1fr;
  }

  .camera-actions,
  .dialog-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .camera-box {
    min-height: 210px;
  }

  .range-grid {
    grid-template-columns: 1fr 1fr;
  }

  .range-grid strong {
    grid-column: 1 / -1;
  }

  .result-columns {
    grid-template-columns: 1fr;
  }

  .play-layout {
    grid-template-columns: 1fr;
    width: calc(100vw - 20px);
  }

  .logic-board {
    min-width: max-content;
  }

  .property-grid {
    grid-template-columns: 1fr;
  }

  .board-scroll {
    max-height: 62vh;
  }

  .board-toolbar {
    gap: 8px;
  }

  .zoom-control {
    width: 100%;
    justify-content: space-between;
  }

  .zoom-control input {
    flex: 1;
    width: auto;
  }
}

@media (orientation: landscape) and (max-height: 560px) {
  .play-view {
    padding-top: 12px;
  }

  .play-layout {
    grid-template-columns: minmax(180px, 28vw) 1fr;
    gap: 10px;
  }

  .source-panel img {
    max-height: 38vh;
  }

  .board-scroll {
    max-height: 58vh;
  }

  .board-toolbar {
    position: sticky;
    top: 0;
  }
}
