:root {
  --bg: #f4efe6;
  --panel: #ffffff;
  --line: #4d4637;
  --cell: #ffffff;
  --cell-hover-bg: #fbf4cf;
  --cell-selected: #8cf4d7;
  --cell-hover: #4a90e2;
  --text: #2b261f;
  --muted: #6f6656;
  --error: #b23b3b;
  --success: #2d7a4c;
  --shadow: 0 18px 40px rgba(43, 38, 31, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  padding: 24px;
  background:
    radial-gradient(circle at top, rgba(255, 255, 255, 0.55), transparent 36%),
    linear-gradient(180deg, #def0f7 0%, var(--bg) 100%);
  color: var(--text);
  font-family: OpenSans, sans-serif;
}

.app,
.grid-shell,
.grid,
.cell,
.cell .glyph,
.cell .typed-glyph,
.cell .fake-glyph,
.info-panel,
.pretitle,
.status-row,
.message {
  -webkit-user-select: none;
  user-select: none;
}

.layout {
  width: min(100%, 1080px);
  min-height: calc(100vh - 48px);
  margin: 0 auto;
  display: grid;
  grid-template-columns: minmax(0, 700px) minmax(260px, 320px);
  gap: 24px;
  align-content: start;
  align-items: stretch;
}

.app {
  width: 100%;
  background: var(--panel);
  border: 2px solid rgba(77, 70, 55, 0.18);
  border-radius: 24px;
  padding: 28px;
  box-shadow: var(--shadow);
}

h1 {
  margin: 0 0 8px;
  font-size: clamp(1.8rem, 3vw, 2.6rem);
  letter-spacing: 0.02em;
}

.pretitle {
  margin: 0 0 8px;
  color: var(--muted);
  font-style: italic;
  line-height: 1.4;
}

.status-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 18px;
  color: var(--muted);
  font-size: 0.95rem;
}

.mode-indicator {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 6px 12px;
  border: 1px solid rgba(31, 79, 130, 0.18);
  border-radius: 999px;
  background: rgba(74, 144, 226, 0.1);
  color: #1f4f82;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  transition: background-color 140ms ease, box-shadow 140ms ease, transform 120ms ease;
}

.mode-indicator:hover {
  background: rgba(74, 144, 226, 0.16);
  box-shadow: 0 8px 18px rgba(31, 79, 130, 0.12);
  transform: translateY(-1px);
}

.mode-indicator:focus-visible {
  outline: 2px solid rgba(74, 144, 226, 0.45);
  outline-offset: 3px;
}

.grid-shell {
  position: relative;
  width: min(100%, calc(100vh - 320px));
  margin: 0 auto;
  padding: 10px;
  border-radius: 20px;
  background: linear-gradient(180deg, rgba(77, 70, 55, 0.06), rgba(77, 70, 55, 0.14));
  transition: opacity 220ms ease, transform 220ms ease;
}

.grid-shell.is-transitioning {
  opacity: 0;
  transform: scale(0.98);
}

.true-info-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  overflow: visible;
}

.true-info-overlay line,
.true-info-overlay polyline,
.true-info-overlay path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.grid {
  position: relative;
  display: grid;
  grid-template-columns: repeat(9, minmax(0, 1fr));
  gap: 0;
  background: transparent;
  border: 0;
}

.cell {
  position: relative;
  aspect-ratio: 1 / 1;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: clamp(1rem, 2vw, 1.35rem);
  cursor: pointer;
  box-shadow: inset 0 0 0 0 transparent;
  transition: background-color 140ms ease, box-shadow 140ms ease, transform 180ms ease, opacity 180ms ease, filter 180ms ease;
  overflow: hidden;
}

.cell-frame,
.cell-content {
  position: absolute;
  inset: 0;
  display: block;
  transform-origin: center;
  transition: background-color 140ms ease, transform 180ms ease, opacity 180ms ease, filter 180ms ease;
}

.cell-frame {
  z-index: 1;
  background: var(--cell);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

.cell-content {
  z-index: 3;
}

.grid[data-mode="edit"] .cell {
  cursor: text;
}

.grid[data-mode="select"] .cell {
  cursor: pointer;
}

.cell[data-col="2"] .cell-frame,
.cell[data-col="5"] .cell-frame {
  border-right: 3px solid var(--line);
}

.cell[data-col="8"] .cell-frame {
  border-right: 3px solid var(--line);
}

.cell[data-row="2"] .cell-frame,
.cell[data-row="5"] .cell-frame {
  border-bottom: 3px solid var(--line);
}

.cell[data-row="8"] .cell-frame {
  border-bottom: 3px solid var(--line);
}

.cell[data-col="0"] .cell-frame {
  border-left: 3px solid var(--line);
}

.cell[data-row="0"] .cell-frame {
  border-top: 3px solid var(--line);
}

.cell[data-filled="true"] {
  font-weight: 700;
}

.cell[data-editable="true"] {
  color: #1f4f82;
}

.cell .glyph {
  position: relative;
  z-index: 3;
  width: 100%;
  height: 100%;
  display: grid;
  place-items: center;
  transform-origin: center;
  transition: transform 180ms ease, opacity 180ms ease, text-shadow 180ms ease, letter-spacing 180ms ease;
}

.cell .true-glyph {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  pointer-events: none;
  font-weight: 700;
  transform-origin: center;
}

.cell .typed-glyph {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  color: #0d4c85;
  font-weight: 700;
  pointer-events: none;
  transform-origin: center;
  transition: opacity 180ms ease, transform 180ms ease, text-shadow 180ms ease;
}

.cell .fake-glyph {
  position: absolute;
  inset: 0;
  z-index: 3;
  display: grid;
  place-items: center;
  font-weight: 700;
  opacity: 0;
  pointer-events: none;
  transform-origin: center;
  transition: opacity 180ms ease, transform 180ms ease, color 180ms ease, text-shadow 180ms ease;
}

.cell-noise,
.cell-lines {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.cell-noise {
  z-index: 3;
  opacity: 0;
  mix-blend-mode: multiply;
}

.cell-lines {
  z-index: 3;
  overflow: visible;
}

.cell-lines line,
.cell-lines path {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cell.is-selected .cell-frame {
  background: var(--cell-selected) !important;
}

.cell:hover .cell-frame {
  background: var(--cell-hover-bg);
}

.cell.is-selected:hover .cell-frame {
  background: var(--cell-selected) !important;
}

.cell.is-active {
  box-shadow: inset 0 0 0 3px var(--cell-hover), 0 0 0 1px rgba(74, 144, 226, 0.2);
}

.cell:focus-visible {
  outline: none;
  box-shadow: inset 0 0 0 3px var(--cell-hover), 0 0 0 1px rgba(74, 144, 226, 0.2);
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-top: 18px;
}

.action {
  border: 1px solid rgba(43, 38, 31, 0.16);
  border-radius: 999px;
  padding: 12px 20px;
  background: #8cf4d7;
  color: black;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  box-shadow: 0 8px 18px rgba(43, 38, 31, 0.14);
  transition: background-color 140ms ease, box-shadow 140ms ease, transform 120ms ease;
}

button.action:disabled {
  background: #d5d9df;
  color: #6c727b;
  cursor: not-allowed;
  box-shadow: 0 6px 12px rgba(43, 38, 31, 0.08);
  transform: none;
}

.action:hover {
  background: #ee86bc;
  box-shadow: 0 12px 24px rgba(43, 38, 31, 0.18);
  transform: translateY(-1px);
}

button.action:disabled:hover {
  background: #d5d9df;
  box-shadow: 0 6px 12px rgba(43, 38, 31, 0.08);
  transform: none;
}

.action:focus-visible {
  outline: 2px solid rgba(74, 144, 226, 0.45);
  outline-offset: 3px;
}

a.action {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
  color: black;
}

.action.is-disabled,
.action.is-disabled:hover {
  background: #d5d9df;
  color: #6c727b;
  cursor: not-allowed;
  box-shadow: 0 6px 12px rgba(43, 38, 31, 0.08);
  transform: none;
  pointer-events: none;
}

#disableNoiseButton.is-noise-disabled,
#disableNoiseButton.is-noise-disabled {
  background: #f4dc8c;
  color: #4f4213;
}

.message {
  min-height: 1.5em;
  font-weight: 700;
}

.message.error {
  color: var(--error);
}

.message.success {
  color: var(--success);
}

.info-panel {
  width: 100%;
  height: 100%;
  background: rgba(255, 255, 255, 0.92);
  border: 2px solid rgba(77, 70, 55, 0.14);
  border-radius: 24px;
  padding: 20px;
  box-shadow: var(--shadow);
  display: grid;
  align-content: start;
  gap: 14px;
}

.info-card {
  padding: 16px;
  border-radius: 18px;
  background: #f9fafc;
  border: 1px solid rgba(77, 70, 55, 0.08);
}

.info-card h2 {
  margin: 0 0 10px;
  font-size: 1.1rem;
}

.info-text {
  margin: 0;
  color: var(--muted);
  line-height: 1.6;
  white-space: pre-wrap;
}

.info-text.is-compact {
  font-size: 0.5em;
  line-height: 1.45;
}

.info-card-scroll {
  min-height: 0;
  overflow: auto;
}

#miningBlock {
  align-self: end;
  margin-top: auto;
}

.info-card .message {
  margin-top: 12px;
}

.mining-progress {
  display: grid;
  gap: 10px;
}

.mining-bar {
  width: 100%;
  height: 14px;
  border-radius: 999px;
  background: #e4ebf3;
  overflow: hidden;
  box-shadow: inset 0 1px 2px rgba(24, 50, 77, 0.12);
}

.mining-bar-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background: linear-gradient(90deg, #78d7bc 0%, #4aa2e2 100%);
  transition: width 180ms ease;
}

.mining-progress-text {
  padding: 10px 12px;
  border-radius: 14px;
  background: #f6f8fb;
  color: #18324d;
  font: 0.88rem/1.4 "Courier New", monospace;
}

.stage-action {
  min-width: 92px;
  padding: 10px 12px;
}


@media (max-width: 640px) {
  .app {
    padding: 20px;
  }
}

@media (max-width: 980px) {
  .layout {
    grid-template-columns: 1fr;
  }
}
