:root {
  --bg: #0b0f14;
  --card: #111827;
  --grid-cell: #0f172a;
  --grid-border: rgba(255, 255, 255, 0.12);
  --text: #e5e7eb;
  --accent: #ff5a1f;
  --select: rgba(255, 90, 31, 0.35);
  --found: rgba(34, 197, 94, 0.35);
  --btn-primary-bg: #ff5a1f;
  --btn-primary-text: #0b0f14;
  --btn-secondary-bg: #1f2937;
  --btn-secondary-text: #e5e7eb;
  --font: "Space Grotesk", "Trebuchet MS", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: radial-gradient(circle at 10% 0%, rgba(255, 90, 31, 0.2), transparent 40%),
    radial-gradient(circle at 90% 15%, rgba(34, 197, 94, 0.2), transparent 45%),
    linear-gradient(180deg, var(--bg) 0%, #05070b 100%);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: -20%;
  background: radial-gradient(circle at 20% 20%, rgba(255, 255, 255, 0.08), transparent 45%),
    radial-gradient(circle at 80% 0%, rgba(255, 90, 31, 0.12), transparent 55%);
  opacity: 0.6;
  pointer-events: none;
  z-index: -1;
}

.app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: calc(18px + env(safe-area-inset-top)) 20px calc(28px + env(safe-area-inset-bottom));
  gap: 16px;
  max-width: 1100px;
  margin: 0 auto;
}

.header {
  display: grid;
  grid-template-columns: minmax(88px, auto) 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
}

.header-right {
  display: flex;
  justify-content: flex-end;
}

.logo-button {
  width: 78px;
  height: 78px;
  border-radius: 22px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: linear-gradient(160deg, rgba(255, 255, 255, 0.14), rgba(255, 255, 255, 0.04));
  display: grid;
  place-items: center;
  cursor: pointer;
  box-shadow: 0 14px 30px rgba(0, 0, 0, 0.4), inset 0 0 0 1px rgba(255, 255, 255, 0.05);
  transition: transform 0.15s ease, box-shadow 0.2s ease, opacity 0.2s ease;
}

.logo-button:active {
  transform: scale(0.98);
}

.logo {
  width: 64px;
  height: 64px;
  object-fit: contain;
  filter: drop-shadow(0 6px 14px rgba(0, 0, 0, 0.5));
}

.hidden {
  display: none !important;
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.brand-text--center {
  align-items: center;
  text-align: center;
}

.title {
  font-size: 24px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
}

.subtitle {
  font-size: 14px;
  opacity: 0.8;
}

.timer {
  font-size: 20px;
  font-weight: 700;
  padding: 10px 14px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
}


.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: 100%;
  max-width: 100%;
  align-self: center;
}

.grid-card,
.words-card {
  background: var(--card);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 18px;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.25);
  width: 100%;
  max-width: 100%;
}

.grid-card {
  flex: 1;
  min-height: 0;
}

.words-card--inline {
  padding: 16px 20px;
}

.grid-wrapper {
  position: relative;
  flex: 1;
  border-radius: 16px;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(15, 23, 42, 0.9), rgba(9, 12, 18, 0.95));
  border: 1px solid var(--grid-border);
  touch-action: none;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.grid {
  width: 100%;
  max-width: 100%;
  max-height: 100%;
  display: grid;
  gap: 4px;
  padding: 10px;
  touch-action: none;
  margin: 0;
  box-sizing: border-box;
}

.cell {
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--grid-cell);
  border-radius: 8px;
  border: 1px solid var(--grid-border);
  font-size: clamp(14px, 2.5vw, 22px);
  font-weight: 700;
  user-select: none;
  transition: background 0.15s ease, box-shadow 0.2s ease;
  text-shadow: 0 2px 6px rgba(0, 0, 0, 0.6);
  min-height: 0;
  aspect-ratio: 1;
}

.cell.selected {
  background: linear-gradient(140deg, rgba(255, 90, 31, 0.45), rgba(255, 165, 79, 0.25));
  transform: scale(1.06);
  box-shadow: 0 0 14px rgba(255, 90, 31, 0.45);
  animation: pulse 0.35s ease;
  will-change: transform, background, box-shadow;
}

.cell.hint {
  background: linear-gradient(140deg, rgba(255, 205, 120, 0.4), rgba(255, 90, 31, 0.18));
  box-shadow: 0 0 16px rgba(255, 170, 80, 0.45);
  will-change: background, box-shadow;
}

.cell.found {
  background: linear-gradient(150deg, rgba(34, 197, 94, 0.45), rgba(34, 197, 94, 0.2));
  box-shadow: inset 0 0 0 1px rgba(34, 197, 94, 0.4);
  transform: none !important;
}

.cell.attract {
  background: linear-gradient(145deg, rgba(255, 170, 95, 0.34), rgba(255, 90, 31, 0.2));
  box-shadow: 0 0 12px rgba(255, 150, 92, 0.4);
  animation: attractPulse 0.7s ease-in-out;
}

@keyframes attractPulse {
  0% { transform: translate(0, 0) scale(1); }
  25% { transform: translate(0.5px, -0.5px) scale(1.02); }
  50% { transform: translate(-0.5px, 0.5px) scale(1.03); }
  75% { transform: translate(0.5px, 0.3px) scale(1.01); }
  100% { transform: translate(0, 0) scale(1); }
}

.grid-overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
}

.grid-overlay .trail-line {
  stroke-width: 8;
  stroke-linecap: round;
  filter: drop-shadow(0 0 10px rgba(255, 90, 31, 0.45));
}

.grid-overlay .trail-dot {
  fill: rgba(255, 225, 180, 0.9);
  filter: drop-shadow(0 0 12px rgba(255, 120, 60, 0.8));
}

.grid-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.status-text {
  min-height: 20px;
  font-size: 14px;
  opacity: 0.8;
}

.words-header {
  display: flex;
  justify-content: center;
  align-items: center;
  padding-bottom: 6px;
  width: 100%;
}

.words-header h2 {
  font-size: 13px;
  font-weight: 700;
  opacity: 0.6;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  margin: 0;
}


.word-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 10px;
  width: 100%;
}

.words-card--inline .word-list {
  flex-wrap: wrap;
  justify-content: center;
  overflow-x: visible;
  row-gap: 14px;
  gap: 12px;
}

.word-list::-webkit-scrollbar {
  height: 6px;
}

.word-list::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.2);
  border-radius: 999px;
}

.word-item {
  padding: 14px 24px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-weight: 800;
  white-space: nowrap;
  font-size: 18px;
  letter-spacing: 0.03em;
  border: 2px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  transition: all 0.2s ease;
  min-height: 52px;
}

.word-item:hover:not(.found) {
  transform: scale(1.05);
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.2);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

.word-item.hint {
  background: rgba(255, 90, 31, 0.25);
  box-shadow: 0 0 20px rgba(255, 90, 31, 0.4);
  border-color: rgba(255, 90, 31, 0.4);
}

.word-item.found {
  text-decoration: line-through;
  opacity: 0.6;
}


.btn {
  border: none;
  border-radius: 14px;
  padding: 12px 16px;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
  min-height: 48px;
  transition: transform 0.15s ease, box-shadow 0.2s ease;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn.primary {
  background: var(--btn-primary-bg);
  color: var(--btn-primary-text);
}

.btn.secondary {
  background: var(--btn-secondary-bg);
  color: var(--btn-secondary-text);
}

.btn.ghost {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.panel {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.85);
  color: var(--text);
  padding: 16px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  z-index: 20;
  backdrop-filter: blur(8px);
}

.panel-shell {
  max-width: min(1180px, calc(100vw - 32px));
  margin: 0 auto;
  width: 100%;
  height: calc(100dvh - 32px);
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
  position: relative;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  padding-right: 96px;
}

.panel-header-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 5;
}

.panel-title h2 {
  margin: 4px 0 0;
  font-size: 26px;
}

.panel-kicker {
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 12px;
  opacity: 0.7;
}

.panel-subtitle {
  font-size: 14px;
  opacity: 0.7;
  margin-top: 6px;
}

.admin-tabs {
  display: flex;
  gap: 8px;
  margin: 6px 0 0;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  padding-bottom: 2px;
  overflow-x: auto;
  scrollbar-width: none;
  flex-shrink: 0;
}
.admin-tabs::-webkit-scrollbar { display: none; }

.admin-tab-btn {
  background: transparent;
  border: none;
  color: var(--text);
  opacity: 0.5;
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  padding: 10px 14px;
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: opacity 0.2s, border-color 0.2s, color 0.2s;
  white-space: nowrap;
}

.admin-tab-btn:hover {
  opacity: 0.8;
}

.admin-tab-btn.active {
  opacity: 1;
  color: var(--accent);
  border-bottom: 2px solid var(--accent);
}

.admin-tab-pane {
  display: none;
  min-height: 0;
}

.admin-tab-pane.active {
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: auto;
  padding: 4px 4px 96px;
  scrollbar-width: thin;
}

.panel-body {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
}

.panel-body.admin-tab-pane {
  display: none;
}

.panel-body.admin-tab-pane.active {
  display: flex;
}

.panel-section {
  background: var(--card);
  border-radius: 10px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 26px rgba(0, 0, 0, 0.2);
  min-height: 0;
  height: auto;
  overflow: visible;
}

.admin-layout {
  display: flex;
  flex-direction: column;
  gap: 14px;
  align-items: stretch;
  max-width: 900px;
  margin: 0 auto;
  width: 100%;
}

.panel-span-2 {
  grid-column: auto;
}

.section-head h3 {
  margin: 0;
}

.section-head p {
  margin: 4px 0 0;
  font-size: 13px;
  opacity: 0.7;
}

.panel-note {
  margin: 0;
  font-size: 12px;
  opacity: 0.7;
}

.panel-footer {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: rgba(17, 24, 39, 0.7);
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  position: fixed;
  left: 50%;
  bottom: 16px;
  transform: translateX(-50%);
  width: min(1180px, calc(100vw - 32px));
  z-index: 5;
  flex-shrink: 0;
  box-shadow: 0 -14px 30px rgba(5, 7, 11, 0.42);
}

.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px;
}

.form-row label {
  display: grid;
  gap: 6px;
  font-size: 14px;
}

.form-row label.checkbox,
label.checkbox {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  min-height: 42px;
}

.checkbox input[type="checkbox"] {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

.form-row input,
.form-row select,
.form-row textarea {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 8px;
  padding: 10px;
  color: var(--text);
  font-family: inherit;
  min-width: 0;
}

.form-row select option {
  color: #0b0f14;
  background: #f8fafc;
}

.form-row input:disabled,
.form-row select:disabled,
.form-row textarea:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

textarea {
  min-height: 140px;
  resize: vertical;
}

.colors-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 10px;
}

.color-input {
  display: grid;
  grid-template-columns: auto 1fr;
  align-items: center;
  gap: 8px;
}

.color-swatch {
  width: 64px;
  height: 64px;
  min-width: 64px;
  min-height: 64px;
  border-radius: 12px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.color-swatch:hover {
  transform: scale(1.05);
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.color-swatch:active {
  transform: scale(0.95);
}

@media (max-width: 600px) {
  .color-swatch {
    width: 48px;
    height: 48px;
    min-width: 48px;
    min-height: 48px;
  }
}

.color-picker-modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.9);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 100;
  padding: 20px;
}

.color-picker-card {
  background: #111827;
  border-radius: 16px;
  padding: 24px;
  display: grid;
  gap: 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  max-width: 400px;
  width: 100%;
}

.color-picker-preview {
  width: 120px;
  height: 120px;
  border-radius: 16px;
  border: 3px solid rgba(255, 255, 255, 0.2);
  margin: 0 auto;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}

.color-picker-input {
  width: 100%;
  height: 80px;
  border-radius: 12px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  padding: 8px;
}

.color-picker-hex {
  font-size: 20px;
  font-weight: 700;
  text-align: center;
  padding: 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-family: 'Courier New', monospace;
  letter-spacing: 0.1em;
}

.color-picker-actions {
  display: flex;
  gap: 12px;
}

.color-presets {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 8px;
}

.color-preset {
  aspect-ratio: 1;
  border-radius: 8px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  cursor: pointer;
  transition: transform 0.15s ease;
}

.color-preset:hover {
  transform: scale(1.1);
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
}

.panel-actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
}

.admin-message {
  font-size: 14px;
  opacity: 0.8;
}

.logo-preview {
  display: grid;
  gap: 8px;
  align-items: start;
}

.logo-preview-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  opacity: 0.6;
}

.logo-preview img {
  width: 120px;
  height: 120px;
  object-fit: contain;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  padding: 12px;
}

.direction-block {
  display: grid;
  gap: 12px;
  min-height: 214px;
}

.directions-section {
  min-height: 310px;
}

.gameplay-section {
  min-height: 360px;
}

.words-config-section {
  min-height: 420px;
}

.system-import-section {
  min-height: 320px;
}

.cloud-sync-section {
  min-height: 320px;
}

.security-section {
  min-height: 190px;
}

.direction-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  width: 172px;
  min-height: 142px;
}

.dir-toggle {
  position: relative;
  display: block;
  width: 52px;
  height: 42px;
  flex: 0 0 52px;
}

.dir-toggle input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.dir-toggle span {
  display: grid;
  place-items: center;
  width: 52px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.08);
  font-weight: 700;
  cursor: pointer;
}

.dir-toggle input:checked + span {
  background: rgba(255, 90, 31, 0.3);
  border-color: rgba(255, 90, 31, 0.6);
  box-shadow: 0 0 12px rgba(255, 90, 31, 0.3);
}

.dir-center {
  grid-area: c;
  display: grid;
  place-items: center;
  width: 52px;
  height: 42px;
  border-radius: 12px;
  border: 1px dashed rgba(255, 255, 255, 0.2);
  opacity: 0.6;
}

.dir-nw,
.dir-n,
.dir-ne,
.dir-w,
.dir-e,
.dir-sw,
.dir-s,
.dir-se {
  grid-area: auto;
}

.direction-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.btn.tiny {
  padding: 8px 12px;
  font-size: 14px;
  min-height: 40px;
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.8);
  display: flex;
  justify-content: center;
  align-items: center;
  padding: 16px;
  z-index: 30;
}

.modal-card {
  background: #111827;
  border-radius: 16px;
  padding: 20px;
  width: min(420px, 100%);
  display: grid;
  gap: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
}

.ranking-card {
  width: min(520px, 100%);
  background: linear-gradient(160deg, rgba(17, 24, 39, 0.95), rgba(7, 10, 16, 0.98));
  box-shadow: 0 18px 40px rgba(0, 0, 0, 0.4);
}

.ranking-card h3 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.ranking-empty {
  padding: 20px;
  text-align: center;
  font-size: 15px;
  opacity: 0.7;
}

.ranking-list {
  display: grid;
  gap: 10px;
  margin: 0;
  padding: 0;
}

.ranking-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.ranking-item.top {
  background: linear-gradient(135deg, rgba(255, 90, 31, 0.25), rgba(255, 199, 128, 0.1));
  border-color: rgba(255, 90, 31, 0.35);
}

.ranking-rank {
  font-weight: 700;
  font-size: 16px;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.08);
  min-width: 44px;
  text-align: center;
}

.ranking-name {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.ranking-time {
  font-size: 16px;
  font-weight: 700;
  color: #ffd28c;
}

.modal-card input {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.08);
  color: var(--text);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.start-countdown-card {
  width: 100%;
  text-align: center;
  display: flex;
  justify-content: center;
  align-items: center;
  background: transparent;
  border: 0;
  box-shadow: none;
  padding: 0;
}

.start-countdown-value {
  font-size: clamp(140px, 28vw, 260px);
  font-weight: 800;
  line-height: 1;
  letter-spacing: 0.04em;
  color: #ffd28c;
  text-shadow: 0 0 24px rgba(255, 210, 140, 0.72), 0 14px 42px rgba(0, 0, 0, 0.55);
}


.rotate-overlay {
  position: fixed;
  inset: 0;
  background: rgba(5, 7, 11, 0.9);
  color: #fff;
  font-size: 20px;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 40;
  text-align: center;
  padding: 20px;
}

@keyframes shake {
  0% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-4px); }
  100% { transform: translateX(0); }
}

.grid-wrapper.shake {
  animation: shake 0.25s linear;
}

.hint-button {
  position: absolute;
  right: 10px;
  bottom: 10px;
  width: 30px;
  height: 30px;
  border-radius: 999px;
  border: 1px solid rgba(255, 255, 255, 0.18);
  background: rgba(255, 255, 255, 0.06);
  color: rgba(255, 255, 255, 0.7);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  opacity: 0.18;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 5;
}

.hint-button:active {
  opacity: 0.6;
  transform: scale(1.05);
}

@keyframes pulse {
  0% { transform: scale(1); }
  40% { transform: scale(1.08); }
  100% { transform: scale(1.06); }
}

@media (min-width: 1920px) {
  .admin-layout {
    grid-template-columns: repeat(4, minmax(280px, 1fr));
  }

  .panel-span-2 {
    grid-column: span 2;
  }
}

@media (max-width: 1400px) {
  .admin-layout {
    grid-template-columns: repeat(3, minmax(280px, 1fr));
  }
}

@media (max-width: 1100px) {
  .admin-layout {
    grid-template-columns: repeat(2, minmax(300px, 1fr));
  }

  .panel-span-2 {
    grid-column: 1 / -1;
  }
}

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

  .panel-span-2 {
    grid-column: auto;
  }

  .app {
    padding: 16px;
  }
}

@media (max-width: 600px) {
  .app {
    padding: calc(12px + env(safe-area-inset-top)) 14px calc(20px + env(safe-area-inset-bottom));
    gap: 12px;
  }

  .header {
    gap: 10px;
  }

  .logo-button {
    width: 64px;
    height: 64px;
    border-radius: 18px;
  }

  .logo {
    width: 52px;
    height: 52px;
  }

  .title {
    font-size: 20px;
    letter-spacing: 0.08em;
  }

  .subtitle {
    font-size: 12px;
  }

  .timer {
    font-size: 16px;
    padding: 8px 10px;
    border-radius: 10px;
  }

  .grid-card {
    padding: 12px;
    border-radius: 16px;
  }

  .grid-wrapper {
    border-radius: 14px;
  }

  .grid {
    padding: 8px;
    gap: 3px;
  }

  .cell {
    border-radius: 6px;
    font-size: clamp(12px, 3.2vw, 18px);
  }

  .grid-actions {
    gap: 8px;
  }

  .btn {
    font-size: 14px;
    padding: 10px 12px;
    min-height: 42px;
  }

  .words-card {
    padding: 14px 16px;
  }

  .words-header h2 {
    font-size: 12px;
  }

  .word-item {
    padding: 12px 20px;
    font-size: 16px;
    min-height: 48px;
  }

}

@media (max-width: 420px) {
  .logo-button {
    width: 56px;
    height: 56px;
  }

  .logo {
    width: 46px;
    height: 46px;
  }

  .title {
    font-size: 18px;
  }
}

@media (orientation: landscape) and (max-width: 900px) {
  .rotate-overlay {
    display: flex;
  }
}

.lead-modal {
  width: min(520px, 100%);
  max-height: 80vh;
  overflow-y: auto;
}

.lead-fields-container {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin: 16px 0;
}

.lead-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.lead-field-label {
  font-weight: 600;
  font-size: 15px;
  letter-spacing: 0.02em;
}

.lead-field input {
  padding: 14px 16px;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.12);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.lead-field input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 90, 31, 0.15);
}

.lead-field input::placeholder {
  color: rgba(255, 255, 255, 0.4);
}

@media (max-width: 600px) {
  .lead-modal {
    width: calc(100% - 32px);
    margin: 16px;
  }
}

  .lead-field input {
    padding: 12px 14px;
    font-size: 16px;
  }
}

.virtual-keyboard {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--card);
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 200;
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.5);
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), bottom 0.3s ease;
  pointer-events: none;
}

body.keyboard-open .modal-card {
  transform: translateY(calc(-20vh - var(--keyboard-offset, 0px)));
  transition: transform 0.3s ease;
}

.virtual-keyboard.active {
  transform: translateY(0);
  pointer-events: auto;
}

.keyboard-header {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 4px;
}

.keyboard-row {
  display: flex;
  justify-content: center;
  gap: 6px;
}

.k-btn {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 8px;
  color: var(--text);
  font-size: 18px;
  font-weight: 600;
  padding: 14px 0;
  min-width: 44px;
  flex: 1;
  max-width: 60px;
  cursor: pointer;
  user-select: none;
  touch-action: manipulation;
  transition: background 0.1s, transform 0.1s;
}

.k-btn:active {
  background: rgba(255, 255, 255, 0.2);
  transform: scale(0.95);
}

.k-btn.k-action {
  background: rgba(255, 90, 31, 0.2);
  border-color: rgba(255, 90, 31, 0.4);
  color: #fff;
  flex: 1.5;
  max-width: 80px;
}

.k-btn.k-space {
  flex: 5;
  max-width: 250px;
}

@media (max-width: 600px) {
  .virtual-keyboard {
    padding: 8px;
    gap: 6px;
  }
  .k-btn {
    min-width: 30px;
    padding: 12px 0;
    font-size: 16px;
  }
}

.lead-fields-config {
  display: grid;
  gap: 16px;
  margin-top: 12px;
}

.lead-field-config {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: 12px;
  padding: 16px;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
  align-items: start;
}

.lead-field-config-header {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.lead-field-config-title {
  font-weight: 600;
  font-size: 14px;
  letter-spacing: 0.02em;
  opacity: 0.9;
}

.lead-field-config-toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
  cursor: pointer;
  user-select: none;
}

.lead-field-config input[type="text"],
.lead-field-config input[type="number"],
.lead-field-config select {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 10px 12px;
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  width: 100%;
}

.lead-field-config input:focus,
.lead-field-config select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 90, 31, 0.1);
}

.lead-field-config input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.lead-field-config label {
  display: grid;
  gap: 6px;
  font-size: 13px;
  font-weight: 500;
  opacity: 0.8;
}

.lead-field-config-actions {
  grid-column: 1 / -1;
  display: flex;
  justify-content: flex-end;
  padding-top: 8px;
}
