:root {
  --print-scale: 1;
  --toolbar-btn-h: 28px;
  --toolbar-gap: 0.18rem;
  --app-shell-pad: 1rem;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: Arial, sans-serif;
  background: #f8fafc;
  color: #1f2937;
  overflow-x: hidden;
}

.container {
  width: 100%;
  max-width: 100vw;
  margin: 0;
  min-height: 100vh;
  background: #ffffff;
  padding: 10px;
  display: flex;
  flex-direction: column;
  border-radius: 0;
  box-shadow: none;
}

body:not(.app-unlocked) .container {
  display: none;
}

#lock-screen {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: #0f172a;
  opacity: 1;
}

body.app-unlocked #lock-screen {
  display: none;
}

.lock-panel {
  width: min(92vw, 360px);
  background: #ffffff;
  border-radius: 14px;
  padding: 1.25rem;
  box-shadow: 0 22px 48px rgba(0, 0, 0, 0.35);
  display: grid;
  gap: 0.7rem;
}

.lock-panel h2 {
  margin: 0;
  font-size: 1.1rem;
  color: #0f172a;
}

.lock-panel p {
  margin: 0;
  font-size: 0.9rem;
  color: #334155;
}

.lock-panel input,
.lock-panel button {
  height: 40px;
}

.lock-language-controls {
  justify-content: center;
  margin-bottom: 0.1rem;
}

.lock-error {
  min-height: 1.1em;
  color: #dc2626 !important;
  font-size: 0.84rem !important;
  margin: 0;
}

h1 {
  margin: 0;
  font-size: 1.1rem;
  line-height: 1.1;
  white-space: nowrap;
}

.app-logo-wrap {
  display: inline-flex;
  align-items: center;
  min-height: 38px;
}

.app-logo {
  width: auto;
  height: 38px;
  object-fit: cover;
  border-radius: 10px;
  border: 1px solid rgba(15, 23, 42, 0.12);
}

.app-logo.is-hidden {
  display: none;
}

.app-logo-fallback {
  display: none;
  font-size: 1.1rem;
  font-weight: 700;
  line-height: 1.1;
  white-space: nowrap;
}

.app-logo-fallback.is-fallback-visible {
  display: inline-block;
}

.top-bar {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 0.16rem;
  margin-bottom: 0.22rem;
  width: 100%;
  margin-left: 0;
  margin-right: 0;
  padding: 0;
}

.toolbar-row {
  display: flex;
  align-items: center;
  gap: var(--toolbar-gap);
  flex-wrap: nowrap;
  min-width: 0;
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
}

.toolbar-row-main {
  overflow: visible;
}

.toolbar-row-actions {
  overflow: visible;
}

.controls {
  display: flex;
  gap: var(--toolbar-gap);
  flex-wrap: nowrap;
  align-items: center;
  margin-bottom: 0;
  font-size: 0.84rem;
  min-width: 0;
}

.mode-controls {
  margin-top: -0.1rem;
}


.language-controls {
  gap: 0.28rem;
  margin-bottom: 0;
}

.ui-mode-btn {
  height: var(--toolbar-btn-h);
  padding: 0 0.45rem;
  font-size: 0.76rem;
  background: #475569;
}

.ui-mode-btn:hover {
  background: #334155;
}

.ui-mode-btn.is-advanced {
  background: #0ea5e9;
}

.ui-mode-btn.is-advanced:hover {
  background: #0284c7;
}

.compact-size-controls {
  gap: 0.16rem;
  margin-bottom: 0;
}

.compact-size-controls label {
  font-size: 0.76rem;
}

.action-controls {
  margin-bottom: 0;
  flex-wrap: nowrap;
  overflow-x: visible;
  gap: var(--toolbar-gap);
  align-items: center;
  row-gap: var(--toolbar-gap);
  padding-bottom: 0;
}

.action-controls > button {
  flex: 0 0 auto;
}

.compact-size-controls,
.action-controls,
.language-controls {
  white-space: nowrap;
}

.action-controls #savedColorsBox {
  margin-left: 0.15rem;
  margin-right: 0.15rem;
}

.action-controls .finish-round-btn {
  margin-left: 0.15rem;
}

.action-controls .toggle-numbers-btn {
  margin-left: 0.04rem;
}

.top-help-btn {
  margin-left: auto;
}

body.ui-beginner .advanced-only {
  display: none !important;
}

.lang-flag {
  min-width: 50px;
  height: var(--toolbar-btn-h);
  padding: 0 0.3rem;
  font-size: 0.78rem;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  border: 1px solid #94a3b8;
  background: #e2e8f0;
  color: #111827;
}

.lang-flag:hover {
  background: #cbd5e1;
}

.lang-flag.is-active {
  outline: 2px solid #0ea5e9;
  outline-offset: 1px;
  background: #f8fafc;
}

.flag-icon {
  width: 18px;
  height: 12px;
  border: 1px solid rgba(15, 23, 42, 0.25);
  border-radius: 2px;
  flex: 0 0 auto;
}

.flag-hu {
  background: linear-gradient(
    to bottom,
    #ce2939 0 33.33%,
    #ffffff 33.33% 66.66%,
    #477050 66.66% 100%
  );
}

.flag-ro {
  background: linear-gradient(
    to right,
    #002b7f 0 33.33%,
    #fcd116 33.33% 66.66%,
    #ce1126 66.66% 100%
  );
}

.flag-en {
  background:
    linear-gradient(to right, transparent 42%, #c8102e 42% 58%, transparent 58%),
    linear-gradient(to bottom, transparent 38%, #c8102e 38% 62%, transparent 62%),
    #012169;
}

input,
button {
  padding: 0.3rem 0.45rem;
  border-radius: 6px;
  font-size: 0.84rem;
}

input {
  width: 78px;
  border: 1px solid #cbd5e1;
}

.size-input {
  width: 3ch;
  min-width: 3ch;
  text-align: center;
  padding: 0.2rem 0.16rem;
}

.size-input::-webkit-outer-spin-button,
.size-input::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}

.size-input[type='number'] {
  -moz-appearance: textfield;
}

button {
  border: 0;
  background: #0ea5e9;
  color: #ffffff;
  cursor: pointer;
  transition: background-color 120ms ease, transform 100ms ease, filter 120ms ease;
}

button:hover {
  background: #0284c7;
}

button:active {
  transform: translateY(1px);
}

.generate-icon-btn {
  min-width: 25px;
  width: 25px;
  height: var(--toolbar-btn-h);
  padding: 0;
  background: #16a34a;
  font-size: 0.9rem;
  line-height: 1;
}

.generate-icon-btn:hover {
  background: #15803d;
}

.mode-btn-after-generate {
  margin-left: 0.35rem;
}

.recent-btn,
.open-btn,
.save-btn,
.export-image-btn,
.print-btn,
.undo-btn,
.redo-btn {
  min-width: 30px;
  width: 30px;
  height: var(--toolbar-btn-h);
  display: inline-grid;
  place-items: center;
  padding: 0;
  font-size: 0.9rem;
  border: 1px solid rgba(15, 23, 42, 0.18);
}

.fill-inverse-btn {
  min-width: 30px;
  width: 30px;
  height: var(--toolbar-btn-h);
  display: inline-grid;
  place-items: center;
  padding: 0;
  border: 1px solid #111827;
  background: linear-gradient(135deg, #ffffff 0 50%, #111827 50% 100%);
  color: #ffffff;
}

.fill-inverse-large {
  width: 34px;
  height: 34px;
  min-width: 34px;
  border-radius: 7px;
  font-size: 0.95rem;
}

.recent-btn {
  width: 26px;
  height: var(--toolbar-btn-h);
  min-width: 26px;
  font-size: 0.78rem;
}

.toggle-numbers-btn {
  font-size: 0.76rem;
  font-weight: 700;
}

#exportSvgBtn {
  min-width: 36px;
  width: 36px;
  font-size: 0.62rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}

#autoSaveBtn.is-active {
  background: #16a34a;
  border-color: rgba(22, 163, 74, 0.45);
}

#autoSaveBtn.is-active:hover {
  background: #15803d;
}

.toggle-numbers-btn.is-active {
  outline: 2px solid #0ea5e9;
  outline-offset: 1px;
}

#selectRectBtn.is-active,
#moveRectBtn.is-active,
#pasteRectBtn.is-active {
  outline: 2px solid #0ea5e9;
  outline-offset: 1px;
}

#copyRectBtn:disabled,
#moveRectBtn:disabled,
#pasteRectBtn:disabled {
  opacity: 0.45;
  cursor: default;
}

.fill-inverse-btn:hover {
  filter: brightness(0.95);
}

.fill-inverse-btn.is-active {
  outline: 2px solid #16a34a;
  outline-offset: 1px;
}

.fill-inverse-icon {
  line-height: 1;
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.5);
}

.finish-round-btn {
  width: 35px;
  height: 35px;
  min-width: 35px;
  border-radius: 999px;
  padding: 0;
  display: inline-grid;
  place-items: center;
  border: 2px solid #dcfce7;
  background:
    radial-gradient(circle at 30% 28%, #bbf7d0 0 24%, transparent 25%),
    linear-gradient(145deg, #22c55e 0%, #16a34a 55%, #15803d 100%);
  color: #ffffff;
  font-size: 1.02rem;
  line-height: 1;
  flex: 0 0 auto;
  box-shadow:
    0 0 0 1px rgba(22, 163, 74, 0.2),
    0 5px 10px rgba(22, 163, 74, 0.24);
  transform: translateY(0);
  transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease;
}

.finish-round-btn:hover {
  filter: brightness(1.05);
  transform: translateY(-1px);
  box-shadow:
    0 0 0 1px rgba(22, 163, 74, 0.24),
    0 7px 12px rgba(22, 163, 74, 0.28);
}

.finish-round-btn:active {
  transform: translateY(0);
  box-shadow:
    0 0 0 2px rgba(22, 163, 74, 0.14),
    0 5px 10px rgba(22, 163, 74, 0.28);
}

.finish-icon {
  line-height: 1;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.28);
}

.recent-icon,
.open-icon,
.save-icon,
.export-image-icon,
.print-icon,
.undo-icon,
.redo-icon {
  line-height: 1;
}

.undo-btn:disabled,
.redo-btn:disabled {
  opacity: 0.45;
  cursor: default;
  filter: grayscale(0.3);
}

#status {
  margin: 0.08rem 0 0.58rem;
  font-size: 0.85rem;
}

.column-result {
  border: 1px solid #cbd5e1;
  display: grid;
  overflow: hidden;
  max-width: 100%;
  margin-bottom: 0.5rem;
  background: #f8fafc;
  min-height: 0;
}

.column-result:empty {
  display: none;
}

.board-scroll {
  width: 100%;
  overflow-x: auto;
  overflow-y: auto;
  flex: 1 1 auto;
  min-height: 0;
  display: block;
}

.main-area {
  width: max-content;
  display: grid;
  grid-template-columns: auto auto;
  grid-template-rows: auto auto;
  column-gap: 0.5rem;
  row-gap: 0.5rem;
  align-items: flex-start;
  justify-content: start;
  align-self: flex-start;
  margin: 0 auto;
}

.cross-result {
  grid-column: 1;
  grid-row: 1;
  border: 1px solid #cbd5e1;
  display: grid;
  overflow: hidden;
  background: #f8fafc;
}

.cross-result:empty {
  display: none;
}

.column-result {
  grid-column: 2;
  grid-row: 1;
}

.row-result {
  grid-column: 1;
  grid-row: 2;
  border: 1px solid #cbd5e1;
  display: grid;
  overflow: hidden;
  max-height: none;
  background: #f8fafc;
  min-width: 0;
}

.row-result:empty {
  display: none;
}

.cross-result .column-drag-handle {
  cursor: grab;
}

.cross-result.dragging-columns .column-drag-handle {
  cursor: grabbing;
}

.cross-result .column-drag-handle:hover {
  box-shadow: inset 0 0 0 2px rgba(14, 165, 233, 0.35);
}

.result-cell {
  width: 25px;
  height: 25px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
}

.result-cell.marked {
  background: #111827;
}

.result-cell.marker-circle {
  position: relative;
  background: #ffffff;
}

.result-cell.marker-circle::after {
  content: '';
  position: absolute;
  inset: 2px;
  border-radius: 999px;
  background: var(--marker-fill, #111827);
}

.grid {
  grid-column: 2;
  grid-row: 2;
  border: 1px solid #cbd5e1;
  display: grid;
  overflow: visible;
  width: max-content;
  max-width: none;
  max-height: none;
}

.cell {
  width: 25px;
  height: 25px;
  border: 1px solid #e2e8f0;
  background: #ffffff;
  cursor: pointer;
  position: relative;
}

.cell.selected {
  border-color: transparent;
}

.cell.selected::before {
  content: '';
  position: absolute;
  top: 1px;
  right: 1px;
  bottom: 1px;
  left: 1px;
  background: var(--cell-color, #0ea5e9);
  border-radius: 18px;
  z-index: 1;
}

.cell.selected.numbered::after {
  content: attr(data-number);
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 0.95rem;
  font-weight: 700;
  color: #ffffff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.45);
  z-index: 2;
  pointer-events: none;
}

body.hide-cell-numbers .cell.selected.numbered::after {
  display: none;
}

.cell.selected.link-h-left::before {
  left: 0;
  border-top-left-radius: 0;
  border-bottom-left-radius: 0;
}

.cell.selected.link-h-right::before {
  right: 0;
  border-top-right-radius: 0;
  border-bottom-right-radius: 0;
}

.cell.selected.link-v-up::before {
  top: 0;
  border-top-left-radius: 0;
  border-top-right-radius: 0;
}

.cell.selected.link-v-down::before {
  bottom: 0;
  border-bottom-left-radius: 0;
  border-bottom-right-radius: 0;
}

.cell.rect-selected {
  background: #eef6ff;
}

.cell.rect-top {
  border-top: 2px dashed #0ea5e9;
}

.cell.rect-right {
  border-right: 2px dashed #0ea5e9;
}

.cell.rect-bottom {
  border-bottom: 2px dashed #0ea5e9;
}

.cell.rect-left {
  border-left: 2px dashed #0ea5e9;
}

#weftBtn,
#warpBtn {
  background: #9ca3af;
  color: #ffffff;
}

#weftBtn.is-active,
#warpBtn.is-active {
  background: #16a34a;
  outline: 2px solid #0ea5e9;
  outline-offset: 1px;
}

#weftBtn:hover,
#warpBtn:hover {
  background: #6b7280;
}

#weftBtn.is-active:hover,
#warpBtn.is-active:hover {
  background: #15803d;
}

.color-controls {
  align-items: flex-start;
  gap: 0.55rem;
}

.color-menu-wrap {
  display: inline-flex;
  align-items: center;
}

.native-color-input {
  width: 30px;
  height: 24px;
  opacity: 1;
  pointer-events: auto;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 1px;
  background: #ffffff;
}

.saved-colors-box {
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  padding: 0.28rem 0.34rem;
  background: #f8fafc;
}

.saved-colors-box > span {
  font-size: 0.78rem;
  display: block;
  margin-bottom: 0.3rem;
}

#colorLabel,
#savedColorsLabel {
  display: none;
}

.saved-colors {
  display: flex;
  gap: 0.2rem;
  flex-wrap: wrap;
  min-height: 18px;
  max-width: 260px;
}

@media (max-width: 900px) {
  :root {
    --app-shell-pad: 0.7rem;
  }

  .container {
    width: 100%;
    padding: 0.65rem 0.7rem 0.85rem;
  }

  .toolbar-row {
    gap: 0.2rem;
  }

  .controls {
    gap: 0.2rem;
  }

  .app-logo-wrap {
    min-height: 34px;
  }

  .app-logo {
    height: 34px;
  }

  .saved-colors {
    max-width: 170px;
  }

  .shortcut-row {
    grid-template-columns: 1fr;
    gap: 0.2rem;
  }
}

.saved-colors button {
  width: 17px;
  height: 17px;
  border-radius: 999px;
  border: 1px solid #64748b;
  padding: 0;
  background: #ffffff;
}

.saved-colors button:disabled {
  cursor: default;
  opacity: 1;
}

.saved-colors button.is-active {
  outline: 2px solid #0f172a;
  outline-offset: 1px;
}

.shortcuts-modal {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 0.8rem;
}

.shortcuts-modal.is-open {
  display: flex;
}

.shortcuts-dialog {
  width: min(540px, 96vw);
  max-height: min(78vh, 640px);
  overflow: auto;
  background: #ffffff;
  border: 1px solid #cbd5e1;
  border-radius: 10px;
  box-shadow: 0 20px 45px rgba(0, 0, 0, 0.28);
  padding: 0.68rem 0.72rem;
}

.shortcuts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.shortcuts-close-btn {
  width: 28px;
  height: 28px;
  min-width: 28px;
  border: 1px solid rgba(15, 23, 42, 0.2);
  background: #e2e8f0;
  color: #111827;
  font-weight: 700;
}

.shortcuts-close-btn:hover {
  background: #cbd5e1;
}

.shortcuts-list {
  display: grid;
  gap: 0.26rem;
  font-size: 0.82rem;
}

.shortcut-row {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 0.4rem;
  align-items: center;
  border: 1px solid #e2e8f0;
  border-radius: 7px;
  padding: 0.28rem 0.42rem;
}

.shortcut-keys {
  font-family: Consolas, 'Courier New', monospace;
  font-size: 0.76rem;
  color: #0f172a;
  background: #f1f5f9;
  border: 1px solid #cbd5e1;
  border-radius: 6px;
  padding: 0.16rem 0.28rem;
  justify-self: start;
}


@page {
  size: A4 landscape;
  margin: 10mm;
}

@media print {
  html,
  body {
    background: #ffffff !important;
    color: #000000 !important;
    margin: 0 !important;
    min-height: auto !important;
    display: block !important;
    place-items: initial !important;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }

  .container {
    width: auto !important;
    max-width: none !important;
    padding: 0 !important;
    margin: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: #ffffff !important;
  }

  .top-bar,
  .action-controls,
  #status,
  .shortcuts-modal {
    display: none !important;
  }

  .board-scroll {
    width: auto !important;
    overflow: visible !important;
  }

  .main-area {
    min-width: 0 !important;
    width: max-content !important;
    margin: 0 !important;
    zoom: var(--print-scale);
    transform-origin: top left;
  }

  .grid,
  .row-result,
  .column-result,
  .cross-result {
    max-height: none !important;
    overflow: visible !important;
  }
}
