:root{
  --cols: 20;
  --rows: 20;
  --gap: 0px; /* no gap between cells */
  --bg: #f6f7f8;
  --cell: #ffffff;
  --accent: #1f8ef1;
  --muted: #d6d9de;
}

*{box-sizing:border-box;margin:0;padding:0}
html,body,#app{height:100%}
body{
  background:var(--bg);
  font-family:system-ui,-apple-system,Segoe UI,Roboto,"Helvetica Neue",Arial;
  -webkit-font-smoothing:antialiased;
  -moz-osx-font-smoothing:grayscale;
  display:flex;
  align-items:center;
  justify-content:center;
  height:100vh;
  width:100vw;
  touch-action: manipulation;
}

/* app layout: left rules panel + grid + palette */
#app{
  display:flex;
  align-items:flex-start;
  gap:18px;
  position:relative;
  padding:12px;
}

/* rules panel on the left */
.rules{
  width:220px;
  background:rgba(255,255,255,0.98);
  border-radius:10px;
  padding:12px;
  box-shadow:0 8px 20px rgba(0,0,0,0.06);
  font-size:13px;
  color:#111;
  flex:0 0 auto;
}
.rules-head{
  font-weight:700;
  margin-bottom:8px;
}
.rules-list{
  list-style:none;
  padding:0;
  margin:0 0 8px 0;
  display:grid;
  gap:6px;
}
.rules-list li{
  background:#fbfbfb;
  border:1px solid var(--muted);
  padding:6px 8px;
  border-radius:6px;
  font-weight:600;
  display:flex;
  align-items:center;
  gap:8px;
}
.rules-note{
  font-size:12px;
  color:#555;
  margin-top:6px;
}

/* container that holds rows */
#grid{
  display:flex;
  flex-direction:column;
  align-items:flex-start; /* important for offsets */
  justify-content:center;
  user-select:none;
  -webkit-tap-highlight-color: transparent;
  background:transparent;
  /* size set by JS via inline style --cell-size and width */
}

/* each row is a horizontal flex container */
.row{
  display:flex;
  gap:var(--gap);
  margin-bottom:var(--gap);
}

/* cell basics */
.cell{
  background:var(--cell);
  border-radius:0;
  box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset, 0 1px 3px rgba(0,0,0,0.04);
  display:inline-block;
  flex: 0 0 auto;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 120ms ease, background-color 160ms ease, box-shadow 160ms ease;
}

/* active/toggled state */
.cell.active{
  background: linear-gradient(180deg, var(--accent), #0f65b8);
  transform: translateY(-3px) scale(1.02);
  box-shadow: 0 6px 14px rgba(31,142,241,0.18);
}

/* subtle focus/press states for accessibility */
.cell:active{ transform: translateY(-1px) scale(1.01); }
.cell:focus{ outline:3px solid rgba(31,142,241,0.18); outline-offset:2px; }

/* small on-screen helper corner (optional, unobtrusive) */
.info {
  position: absolute;
  left:12px;
  bottom:12px;
  background: rgba(255,255,255,0.95);
  border-radius:10px;
  padding:8px;
  font-size:13px;
  color:#222;
  box-shadow:0 6px 18px rgba(0,0,0,0.06);
  user-select:none;
  display:flex;
  align-items:center;
  gap:6px;
}

/* palette swatches */
.swatch{
  display:flex;
  align-items:center;
  gap:6px;
  background:transparent;
  padding:4px;
  border-radius:6px;
  cursor:pointer;
  user-select:none;
}
.swatch input[type="radio"]{
  width:18px;
  height:18px;
  margin:0;
  accent-color: #1f8ef1;
}
.swatch .label{
  font-weight:700;
  font-size:12px;
  width:14px;
  display:inline-block;
  text-align:center;
}
.color-input{
  width:28px;
  height:28px;
  padding:0;
  border-radius:6px;
  border:1px solid var(--muted);
  background:#fff;
  -webkit-appearance:none;
}
.color-input::-webkit-color-swatch-wrapper{padding:0}
.color-input::-webkit-color-swatch{border-radius:6px}

.white-swatch{
  width:28px;
  height:28px;
  border-radius:6px;
  background:#fff;
  border:1px solid var(--muted);
  box-shadow: inset 0 1px 0 rgba(0,0,0,0.02);
}

/* add a little focus ring for accessibility */
.color-input:focus, .swatch input[type="radio"]:focus{
  outline:3px solid rgba(31,142,241,0.18);
  outline-offset:2px;
}