:root{
  --bg: #0f1115;
  --panel: #151923;
  --panel2:#101521;

  --text: #e7e9ee;
  --muted: #9aa3b2;
  --border: rgba(255,255,255,.10);

  --good: #2ecc71;
  --bad: #ff4d4d;
  --accent: #7aa2ff;

  /* Tell UA we are dark (scrollbars, form controls, etc.) */
  color-scheme: dark; /* [page:4] */

  /* Material system tokens (dark) */
  --md-sys-color-primary: var(--accent);
  --md-sys-color-on-surface: var(--text);
  --md-sys-color-on-surface-variant: var(--muted);

  --md-sys-color-surface: #121622;
  --md-sys-color-surface-container: #151b2a;
  --md-sys-color-surface-container-high: #1a2236;
  --md-sys-color-outline: rgba(255,255,255,.22);
}

*{ box-sizing: border-box; }
html,body{ height:100%; }

body{
  margin:0;
  font-family: Roboto, system-ui, -apple-system, Segoe UI, Arial, sans-serif;
  color: var(--text);
  background: radial-gradient(1200px 600px at 20% 0%, #1b2340 0%, var(--bg) 60%) fixed;
}

/* --- Topbar --- */
.topbar{
  display:flex;
  align-items:center;
  justify-content:space-between;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
  background: rgba(10,12,18,.6);
  backdrop-filter: blur(10px);
  position: sticky;
  top:0;
  z-index: 5;
}

/* --- Layout --- */
.container{
  display:grid;
  grid-template-columns: 340px 1fr;
  gap: 16px;
  padding: 16px;
  max-width: 1400px;
  margin: 0 auto;
}

.panel{
  background: rgba(21,25,35,.75);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.panelHeader{
  display:flex;
  align-items:center;
  justify-content:space-between;
  margin-bottom: 10px;
}

.setupGrid{ display:grid; gap: 10px; }
.row{ display:flex; gap: 10px; flex-wrap: wrap; align-items:center; }
.hint{ color: var(--muted); }

.colsBlock{ margin-top: 14px; }
.colsList{
  display:grid;
  gap: 8px;
  margin-top: 8px;
  padding: 10px;
  border: 1px dashed var(--border);
  border-radius: 12px;
  min-height: 90px;
}
.colsItem{ display:flex; gap: 10px; align-items:center; }
.muted{ color: var(--muted); }

/* --- Board --- */
.board{
  background: rgba(16,21,33,.55);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
  min-height: 70vh;
}

.boardHeader{
  display:flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 10px;
  margin: 6px 0 10px;
}

.cardPool{
  display:flex;
  flex-wrap: wrap;
  gap: 10px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(0,0,0,.12);
  min-height: 120px;
}

/* --- Card --- */
.card{
  background: rgba(255,255,255,.06);
  border: 1px solid rgba(255,255,255,.14);
  border-radius: 14px;
  padding: 10px 10px;
  min-width: 120px;
  max-width: 240px;
  cursor: grab;
  user-select: none;
  position: relative;
  box-shadow: 0 10px 20px rgba(0,0,0,.25);

  /* for mobile drag */
  touch-action: none;
}

.card.dragging{
  position: fixed;
  z-index: 9999;
  cursor: grabbing;
  transform: none !important;
  pointer-events: none;
}

.card.locked{
  cursor: default;
  opacity: .85;
  border-color: rgba(46, 204, 113, .5);
}

.cardText{
  white-space: pre-wrap;
  word-break: break-word;
  padding-right: 34px;
}

.cardMeta{
  position:absolute;
  top: 8px;
  right: 8px;
  display:flex;
  gap: 6px;
  align-items:center;
}

.badge{
  font-size: 12px;
  color: rgba(255,255,255,.75);
  border: 1px solid rgba(255,255,255,.18);
  padding: 1px 6px;
  border-radius: 999px;
}

.hintBtn{
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.06);
  color: rgba(255,255,255,.85);
  cursor: pointer;
  touch-action: manipulation;
}
.hintBtn:active{ transform: scale(.98); }

.card.highlight{
  outline: 2px solid var(--accent);
  box-shadow: 0 0 0 4px rgba(122,162,255,.18);
}

/* Disable page touch scroll only while dragging */
body.draggingPage{
  touch-action: none;
}

/* --- Groups / slots --- */
.groups{
  display:grid;
  gap: 10px;
  margin-top: 10px;
}

.group{
  border: 1px solid var(--border);
  border-radius: 14px;
  background: rgba(0,0,0,.10);
  padding: 10px;
}

.group.good{ border-color: rgba(46,204,113,.55); background: rgba(46,204,113,.08); }
.group.bad{ border-color: rgba(255,77,77,.55); background: rgba(255,77,77,.06); }

.groupTitle{
  display:flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 8px;
}

.slots{
  display:grid;
  gap: 8px;
}

.slot{
  border: 1px dashed rgba(255,255,255,.18);
  border-radius: 12px;
  min-height: 54px;
  padding: 6px;
  background: rgba(255,255,255,.03);
  overflow: hidden;
}

.slotLabel{
  font-size: 11px;
  color: rgba(255,255,255,.45);
  margin-bottom: 4px;
}

.slotInner{
  min-height: 28px;
  overflow: hidden;
}

/* Critical: cards must fit inside slots */
.slotInner .card{
  width: 100%;
  max-width: 100%;
  min-width: 0;
  box-shadow: none;
}

/* --- Dialog / import --- */
.dialogContent{ display:grid; gap: 12px; }
.dialogRow{ display:flex; gap: 10px; align-items:center; }

.label{ color: var(--muted); width: 110px; }

.select{
  flex: 1;
  height: 36px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: rgba(0,0,0,.20);
  color: var(--text);
  padding: 0 10px;
}

.preview{
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: auto;
  max-height: 220px;
  background: rgba(0,0,0,.20);
}

table{ width:100%; border-collapse: collapse; }
th,td{
  padding: 8px 10px;
  border-bottom: 1px solid rgba(255,255,255,.08);
  font-size: 12px;
}
th{
  color: rgba(255,255,255,.70);
  text-align:left;
  position: sticky;
  top: 0;
  background: rgba(0,0,0,.35);
}

.error{ color: var(--bad); font-size: 12px; }

/* Material Web text field tokens (outlined) */
md-outlined-text-field{
  --md-outlined-text-field-input-text-color: var(--text);
  --md-outlined-text-field-label-text-color: var(--muted);
  --md-outlined-text-field-outline-color: rgba(255,255,255,.25);
  --md-outlined-text-field-focus-outline-color: var(--accent);
}

/* Dropzone */
.dropzone{
  border: 1px dashed rgba(255,255,255,.25);
  border-radius: 14px;
  padding: 16px;
  text-align: center;
  color: var(--muted);
  background: rgba(0,0,0,.18);
  cursor: pointer;
}
.dropzone.over{
  border-color: var(--accent);
  color: var(--text);
  box-shadow: 0 0 0 4px rgba(122,162,255,.15);
}

/* Responsive dialog sizing (mobile-safe) */
md-dialog{
  margin: auto;              /* keep centered */
  width: min(96vw, 640px);
  max-width: 96vw;

  max-height: 90vh;
  max-height: 90dvh;

  --md-dialog-container-color: rgba(21, 27, 42, .98);
  --md-dialog-headline-color: var(--text);
  --md-dialog-supporting-text-color: var(--muted);
}

/* Ensure dialog content scrolls instead of going off screen */
.dialogContent{
  max-height: 65vh;
  max-height: 65dvh;
  overflow: auto;
}

/* --- Responsive --- */
@media (max-width: 900px){
  .container{
    grid-template-columns: 1fr;
    padding: 10px;
  }

  .topbar{
    padding: 12px 12px;
  }

  .panel, .board{
    padding: 12px;
  }

  /* Mobile: make the pool a 2-column grid (guarantees 2 columns -> multiple rows) */
  .cardPool{
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;

    max-height: 240px;     /* ~2 rows visible, scroll for more */
    overflow-y: auto;
    align-content: start;
  }

  /* In pool, cards fill the grid cell */
  .cardPool .card{
    width: 100%;
    max-width: 100%;
    min-width: 0;
  }

  /* Keep text compact only in pool */
  .cardPool .cardText{
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
  }

  /* For many columns (4–6), allow horizontal scroll per group row */
  .slots{
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  .preview{
    max-height: 180px;
  }

  md-dialog{
    margin: 12px;           /* give space from edges on small screens */
  }
}

/* Screen-edge success flash */
body.successFlash::before{
  content:"";
  position: fixed;
  inset: 0;
  border: 6px solid rgba(46, 204, 113, .45);
  pointer-events: none;
  z-index: 100000;
  animation: successFlash 0.55s ease-out;
}

@keyframes successFlash{
  from { opacity: 1; }
  to   { opacity: 0; }
}

/* Group solved pop */
.group.justSolved{
  animation: solvedPop 0.35s ease-out;
}

@keyframes solvedPop{
  from { transform: scale(0.985); }
  to   { transform: scale(1); }
}
