:root {
  --bg: #0b0d10;
  --panel: #12151a;
  --panel-2: #0f1216;
  --text: #e6ebf1;
  --muted: #99a3b2;
  --primary: #4f8cff;
  --primary-600: #2f6ff0;
  --border: #1b2027;
  --key-top: #f7f8fa;
  --key-side: #e5e9f0;
  --key-text: #111317;
}

/* light theme variables */
:root.theme-light {
  --bg: #f6f7fb;
  --panel: #ffffff;
  --panel-2: #f5f7fb;
  --text: #0f1722;
  --muted: #5b6574;
  --primary: #2962ff;
  --primary-600: #1e4ed5;
  --border: #e6e8ef;
  --key-top: #f7f8fa;
  --key-side: #e5e9f0;
  --key-text: #111317;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: radial-gradient(1200px 800px at 10% -10%, #10151b, var(--bg)) fixed;
  color: var(--text);
  font: 400 16px/1.4 system-ui, -apple-system, Segoe UI, Roboto, Ubuntu, Cantarell, Noto Sans, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
}

/* Light theme background override for less contrast halo */
:root.theme-light body {
  background: radial-gradient(1200px 800px at 10% -10%, #e9edf6, var(--bg)) fixed;
}

.container {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 20px 40px;
}

.header h1 { margin: 0 0 4px; font-size: 28px; margin-top: 1rem; }
.header .sub { margin: 0; color: var(--muted); font-size: 13px; }

.settings {
  display: grid;
  grid-template-columns: 1.2fr auto auto auto;
  gap: 16px;
  align-items: end;
  margin: 16px 0 8px;
  padding: 16px;
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: 12px;
}

.toolbar {
  display: grid;
  grid-template-columns: 1fr 1.4fr auto;
  grid-template-areas:
    "shortcut label add";
  gap: 16px;
  align-items: end;
  margin: 20px 0 22px;
  padding: 16px 16px 28px; /* extra bottom padding for hint */
  background: linear-gradient(180deg, var(--panel), var(--panel-2));
  border: 1px solid var(--border);
  border-radius: 12px;
}

.field-group { display: grid; gap: 8px; position: relative; }
.label { font-size: 12px; color: var(--muted); }

.text-input, .select-input {
  width: 100%;
  height: 38px;
  color: var(--text);
  background: #0c1015;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 12px;
  outline: none;
}
.text-input:focus, .select-input:focus { border-color: #2a3240; box-shadow: 0 0 0 3px rgb(79 140 255 / 14%); }
.text-input::placeholder { color: var(--muted); }

.text-input.is-error { border-color: #e5484d; box-shadow: 0 0 0 3px rgb(229 72 77 / 18%); }
.select-input.is-error { border-color: #e5484d; box-shadow: 0 0 0 3px rgb(229 72 77 / 18%); }

.shortcut-capture { display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: center; }
.toolbar > .field-group:nth-of-type(1) { grid-area: shortcut; }
.toolbar > .field-group:nth-of-type(2) { grid-area: label; }
.toolbar > .actions { grid-area: add; display: flex; justify-content: flex-end; align-items: end; align-self: end; }
.shortcut-input { cursor: text; }
.hint { color: var(--muted); font-size: 11px; margin-top: 0; position: absolute; left: 0; bottom: -18px; }

.actions { display: flex; gap: 10px; align-items: center; justify-content: flex-end; }
.btn {
  height: 38px;
  padding: 0 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: #0e1319;
  color: var(--text);
  cursor: pointer;
}
.btn:hover { border-color: #2a3240; }
.btn:active { transform: translateY(1px); }
.btn-primary { background: linear-gradient(180deg, var(--primary), var(--primary-600)); border-color: transparent; }
.btn-secondary { background: #121822; }
.btn-ghost { background: transparent; }
.theme-toggle { position: absolute; top: 0; right: 0; margin: 8px; }
.header { position: relative; }
.header-actions { position: absolute; top: 0; right: 0; display: inline-flex; gap: 6px; align-items: center; margin: 8px; }
.lang-toggle { min-width: 68px; }
.lang-dropdown { position: relative; }
.lang-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  min-width: 180px;
  padding: 6px 6px;
  margin: 0;
  list-style: none;
  z-index: 1200;
  box-shadow: 0 8px 24px rgba(0,0,0,0.24);
}
.lang-menu li {
  padding: 8px 10px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 8px;
}
.lang-menu li:hover { background: #0e1319; }
:root.theme-light .lang-menu { background: #ffffff; }
:root.theme-light .lang-menu li:hover { background: #eef2fa; }

/* Light theme control surfaces */
:root.theme-light .text-input,
:root.theme-light .select-input {
  background: #ffffff;
  border-color: var(--border);
  color: var(--text);
}
:root.theme-light .text-input:focus,
:root.theme-light .select-input:focus {
  border-color: #c9d3e4;
  box-shadow: 0 0 0 3px rgb(41 98 255 / 18%);
}

:root.theme-light .text-input.is-error,
:root.theme-light .select-input.is-error {
  border-color: #e5484d;
  box-shadow: 0 0 0 3px rgb(229 72 77 / 18%);
}

:root.theme-light .btn {
  background: #f5f7fb;
  border-color: var(--border);
  color: var(--text);
}
:root.theme-light .btn-secondary { background: #eef2fa; }
:root.theme-light .btn-ghost { background: transparent; }

.cheatsheet-wrap { margin-top: 8px; }
.sheet-title { margin: 10px 4px 12px; font-size: 18px; font-weight: 600; }
.empty { color: var(--muted); font-size: 14px; margin: 20px 4px; }

/* Site footer */
.site-footer {
  margin-top: 2rem;
  color: var(--muted);
}
.site-footer .container {
  padding-top: 16px;
  padding-bottom: 24px;
}
.site-footer p {
  margin: 0;
  font-size: 12px;
  text-align: center;
}

.cheatsheet {
  display: grid;
  gap: 12px;
}

.cheatsheet[data-columns="1"] { grid-template-columns: repeat(1, minmax(0, 1fr)); }
.cheatsheet[data-columns="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.cheatsheet[data-columns="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }

.cheat-item {
  background: linear-gradient(180deg, #12161e, #0f131a);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 14px 12px;
  position: relative;
  height: min-content;
}

/* Column layout containers for vertical flow */
.cheatsheet {
  display: grid;
}
.sheet-col { display: grid; gap: 12px; min-height: 20px; align-content: start; }
.sheet-col.drag-over { outline: 2px dashed var(--primary); outline-offset: 2px; border-radius: 10px; }

/* Intra-column DnD marker */
.cheat-item.drag-before { box-shadow: inset 0 2px 0 var(--primary); }
.cheat-item.drag-after { box-shadow: inset 0 -2px 0 var(--primary); }

/* Visible column break marker (works in both grid and column flows) */
/* Legacy: no longer used but keep minimal visibility if any remain in DOM */
.cheat-break { display: none; }

/* Divider styling */
.cheat-divider {
  background: transparent !important;
  border: none !important;
  cursor: grab;
}
.cheat-divider:active {
  cursor: grabbing;
}
.cheat-divider .item-remove {
  display: none;
}
.cheat-divider:hover .item-remove {
  display: inline-block;
}
.divider-spacer {
  opacity: 0;
  pointer-events: none;
  color: transparent;
  font-size: 13px;
  font-weight: bold;
  grid-column: 1 / -1;
}

/* Remove button used by items and breaks */
.item-remove {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #0e1319;
  color: var(--muted);
  cursor: pointer;
  line-height: 1;
}
.item-remove:hover { border-color: #2a3240; color: var(--text); }
.cheat-item .item-remove { display: none; }
.cheat-item:hover .item-remove { display: inline-block; }

/* Light theme adjustments for remove buttons and breaks */
:root.theme-light .item-remove {
  background: #f5f7fb;
  border-color: var(--border);
  color: #4b5567;
}
:root.theme-light .item-remove:hover {
  border-color: #c9d3e4;
  color: #0f1722;
}
:root.theme-light .cheat-break {
  background: linear-gradient(180deg, #ffffff, #f7f9fc);
  border-color: #c9d3e4;
  color: #5b6574;
}

/* Light theme: use light card surface */
:root.theme-light .cheat-item {
  background: linear-gradient(180deg, #ffffff, #f7f9fc);
  border-color: var(--border);
}

.item-keys { display: flex; flex-wrap: wrap; gap: 6px; margin: 0 0 8px; }
.item-label { color: var(--muted); font-size: 13px; font-weight: bold; white-space: pre-wrap; }

/* Normal mode: place label first and keys to the right using grid */
.cheat-item { display: grid; grid-template-columns: 1fr auto; align-items: center; }
.cheat-item .item-label { grid-column: 1; }
.cheat-item .item-keys { grid-column: 2; justify-self: end; margin: 0; }

/* keycap */
.keycap {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 26px;
  padding: 4px 8px;
  background: linear-gradient(180deg, var(--key-top), var(--key-side));
  color: var(--key-text);
  border: 1px solid #cfd6df;
  border-bottom-color: #b9c2cd;
  border-radius: 6px;
  box-shadow: 0 1px 0 #ffffff, 0 2px 0 #aeb8c4;
  font: 600 12px/1 "SF Pro Text", ui-sans-serif, system-ui, -apple-system, Segoe UI;
  user-select: none;
}

.keycap.combo-joiner {
  background: transparent;
  color: var(--muted);
  border: none;
  box-shadow: none;
  min-width: 0;
  padding: 0 2px;
}

.sheet-header { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.sheet-actions { display: inline-flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.sheet-actions .btn { height: 32px; padding: 0 12px; }

/* Hide native file input used for JSON import */
#importJsonInput { display: none; }

/* Float theme & language toggles as fixed FABs on mobile */
.theme-toggle, .lang-toggle { position: fixed; top: 10px; right: 10px; margin: 0; z-index: 1000; }
.lang-toggle { right: 58px; }

@media (max-width: 800px) {
  .settings { grid-template-columns: 1fr; }
  .toolbar { grid-template-columns: 1fr; grid-template-areas: "shortcut" "label" "add"; }
  .actions { justify-content: stretch; }
  .cheatsheet[data-columns="3"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  /* Stack header and wrap actions under the title */
  .sheet-header { flex-direction: column; align-items: flex-start; gap: 8px; }
  .sheet-actions { display: flex; flex-wrap: wrap; gap: 8px; }
}

@media print {
  @page { size: A4 portrait; margin: 10mm; }
  html, body { background: #ffffff !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  body { font-stretch: normal; letter-spacing: normal; }
  .header, .settings, .toolbar { display: none !important; }
  .sheet-actions { display: none !important; }
  .theme-toggle { display: none !important; }
  .site-footer { display: none !important; }
  .empty { display: none !important; }
  .container { max-width: unset; padding: 0; }
  .cheatsheet-wrap { margin: 0; }
  .sheet-title { margin: 0 0 8px; font-size: 16px; font-stretch: normal; letter-spacing: normal; }
  .cheatsheet { gap: 8px; }
  .sheet-col { break-inside: avoid; page-break-inside: avoid; }
  .cheat-item { break-inside: avoid; page-break-inside: avoid; font-stretch: normal; letter-spacing: normal; }
  .item-label { font-stretch: normal; letter-spacing: normal; }
  .item-remove { display: none !important; }
}

/* Slight tweaks when exporting via html2pdf to reduce shadows for clarity */
:root.exporting-pdf body {
  font-family: Arial, sans-serif !important;
  font-stretch: normal !important;
  letter-spacing: normal !important;
  font-variant: normal !important;
}
:root.exporting-pdf .header { display: none !important; }
:root.exporting-pdf .settings { display: none !important; }
:root.exporting-pdf .toolbar { display: none !important; }
:root.exporting-pdf .sheet-actions { display: none !important; }
:root.exporting-pdf .empty { display: none !important; }
:root.exporting-pdf .theme-toggle { display: none !important; }
:root.exporting-pdf .site-footer { display: none !important; }
:root.exporting-pdf .cheat-item {
  box-shadow: none;
  font-stretch: normal !important;
  letter-spacing: normal !important;
  font-variant: normal !important;
}
:root.exporting-pdf .item-label {
  font-stretch: normal !important;
  letter-spacing: normal !important;
  font-variant: normal !important;
  font-weight: 600 !important;
}
:root.exporting-pdf .keycap {
  font-stretch: normal !important;
  letter-spacing: normal !important;
  font-variant: normal !important;
}
:root.exporting-pdf .container {
  max-width: unset;
  padding: 0;
  font-stretch: normal !important;
  letter-spacing: normal !important;
  font-family: Arial, sans-serif !important;
}
:root.exporting-pdf .cheatsheet-wrap {
  margin: 0;
}
:root.exporting-pdf .sheet-title {
  margin: 0 0 8px;
  font-size: 16px;
  font-stretch: normal !important;
  letter-spacing: normal !important;
  font-variant: normal !important;
}

.cheatsheet[data-density="dense"] .cheat-item {
  padding: 10px 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  align-items: center;
}
.cheatsheet[data-density="dense"] .item-keys { gap: 4px; margin: 0; grid-column: 2; justify-self: end; }
.cheatsheet[data-density="dense"] .item-label { margin: 0; color: var(--muted); font-size: 12px; font-weight: 600; grid-column: 1; justify-self: start; white-space: pre-wrap; }
.cheatsheet[data-density="dense"] .divider-spacer { font-size: 12px; }


