:root {
    --bg-color: #121212;
    --panel-color: #1e1e1e;
    --grid-gap: 6px;
    --cell-size: 55px;
    --off-color: #2a2a2a;

    /* Tile Type Colors */
    --color-std: #00ffcc;   /* Cyan */
    --color-bish: #d500f9;  /* Purple */
    --color-bomb: #ff3d00;  /* Orange */
    --color-wall: #607d8b;  /* Grey */
    --color-archer: #76ff03;/* Lime */
    --color-heavy: #2979ff; /* Blue */
    --color-mirror: #00bcd4; /* Teal */

    --text-color: #e0e0e0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-color);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    display: flex;
    flex-direction: row;
    align-items: flex-start;
    justify-content: center;
    min-height: 100vh;
    margin: 0;
    gap: 40px;
    padding: 40px;
    box-sizing: border-box;
}

h1 { margin: 0 0 20px 0; text-transform: uppercase; letter-spacing: 2px; font-size: 1.5rem; text-align: center;}

/* --- LEFT COLUMN (Dev & Help) --- */
.left-column {
    display: flex;
    flex-direction: column;
    gap: 25px;
    width: 320px;
    position: sticky;
    top: 40px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

/* --- PANELS --- */
.panel {
    background: var(--panel-color);
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #333;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    box-sizing: border-box;
}

/* --- DEV MENU STYLES --- */
.control-group { margin-bottom: 12px; }

.control-label-row { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.control-group label { font-size: 0.85rem; color: #aaa; font-weight: bold; margin: 0; }

.control-group input, .control-group select {
    width: 100%;
    padding: 8px;
    background: #121212;
    border: 1px solid #444;
    color: #fff;
    border-radius: 4px;
    box-sizing: border-box;
}

/* Make number input arrow buttons visible */
.control-group input[type="number"]::-webkit-inner-spin-button,
.control-group input[type="number"]::-webkit-outer-spin-button {
    opacity: 1;
    filter: invert(1);
}

.control-group input[type="number"] {
    -moz-appearance: textfield;
}

.control-group input[type="number"]:hover::-webkit-inner-spin-button,
.control-group input[type="number"]:hover::-webkit-outer-spin-button {
    opacity: 1;
}

.dual-input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 10px;
}
.dual-input-wrapper label {
    font-size: 0.7rem;
    color: #666;
    margin-bottom: 2px;
    display: block;
}

.divider { border-bottom: 1px solid #333; margin: 15px 0; }

button.primary-btn {
    width: 100%;
    padding: 12px;
    background: var(--color-std);
    color: #000;
    border: none;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    text-transform: uppercase;
    transition: 0.2s;
    margin-top: 10px;
}
button.primary-btn:hover { background: #fff; box-shadow: 0 0 15px var(--color-std); }

/* --- COMPATIBILITY NOTE --- */
.algo-note {
    margin-top: 15px;
    padding-top: 15px;
    border-top: 1px dashed #444;
    font-size: 0.75rem;
    color: #777;
}
.algo-note h4 { margin: 0 0 5px 0; color: #aaa; text-transform: uppercase; font-size: 0.85rem; }
.algo-note ul { padding-left: 20px; margin: 5px 0; }
.algo-note li { margin-bottom: 2px; color: #579e57; }
.algo-note span.warn { color: #d65858; display: block; margin-top: 8px; font-style: italic;}

/* --- HOW TO PLAY PANEL --- */
.how-to-play h2 {
    margin: 0 0 15px 0;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-size: 1.2rem;
    text-align: center;
    color: var(--text-color);
}
.how-to-play p {
    font-size: 0.9rem;
    line-height: 1.4;
    margin-bottom: 10px;
    color: #ccc;
}
.how-to-play ul {
    padding-left: 20px;
    margin: 10px 0;
    font-size: 0.85rem;
}
.how-to-play li {
    margin-bottom: 8px;
    color: #aaa;
    line-height: 1.3;
}
.tile-legend-item {
    font-weight: bold;
    display: inline-block;
    width: 85px;
}

/* --- TOOLTIPS --- */
.tooltip-icon {
    background: #333;
    color: #fff;
    border-radius: 50%;
    width: 18px;
    height: 18px;
    font-size: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: help;
    position: relative;
}

.tooltip-icon:hover::after {
    content: attr(data-tip);
    position: absolute;
    left: 25px;
    top: 50%;
    transform: translateY(-50%);
    background: #000;
    border: 1px solid var(--color-std);
    color: #fff;
    padding: 10px;
    border-radius: 6px;
    width: 220px;
    font-size: 0.8rem;
    line-height: 1.4;
    z-index: 100;
    box-shadow: 0 5px 15px rgba(0,0,0,0.8);
    pointer-events: none;
}

/* --- GAME AREA (Right Panel) --- */
.game-area {
    display: flex;
    flex-direction: column;
    align-items: center;
}

.stats-container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 15px;
    margin-bottom: 20px;
    font-size: 1rem;
    text-align: center;
    background: #1e1e1e;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #333;
    width: 100%;
    box-sizing: border-box;
}

.stat-box small { display: block; color: #888; font-size: 0.75rem; text-transform: uppercase; }
.stat-box span { font-size: 1.2rem; font-weight: bold; color: #fff; }
.highlight { color: var(--color-std) !important; }

/* Reveal button for "To Win" */
.reveal-box {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
}

.reveal-btn {
    background: var(--color-std);
    color: #000;
    border: none;
    padding: 8px 16px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    font-weight: bold;
    text-transform: uppercase;
    transition: all 0.2s;
}

.reveal-btn:hover {
    background: #fff;
    box-shadow: 0 0 15px var(--color-std);
    transform: scale(1.05);
}

.reveal-btn:disabled {
    display: none;
}

.hidden-value {
    display: none;
    flex-direction: column;
}

.hidden-value.revealed {
    display: flex;
}

#game-grid {
    display: grid;
    grid-gap: var(--grid-gap);
    padding: 20px;
    background: #1a1a1a;
    border-radius: 15px;
    box-shadow: inset 0 0 20px #000;
}

#game-grid.grid--fade-in .cell {
    opacity: 0;
}

#game-grid.grid--fade-in.grid--fade-in-active .cell {
    opacity: 1;
}

#game-grid.grid--loading .cell {
    opacity: 0;
}

/* --- CELL STYLING --- */
.cell {
    width: var(--cell-size);
    height: var(--cell-size);
    background-color: var(--off-color);
    border-radius: 8px;
    cursor: pointer;
    border: 2px solid #333;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem; /* Standard Size */
    color: #444;
    transition: all 0.15s ease, opacity 1s ease;
    user-select: none;
    box-sizing: border-box;
}

.cell:hover { border-color: #666; transform: scale(1.05); z-index: 5;}

/* --- Specific OFF State Styling --- */
.cell[data-type="wall"] { background: #1a1a1a; border-color: #222; cursor: not-allowed; color: #333; }

/* UNIFIED SPECIAL TILE STYLING: LARGE & BOLD */
.cell[data-type="heavy"],
.cell[data-type="bishop"],
.cell[data-type="bomb"],
.cell[data-type="archer"],
.cell[data-type="mirror"] {
    font-size: 2.1rem;
    font-weight: 500;
    /* Add a subtle drop shadow to make them pop even when OFF */
    text-shadow: 0 0 5px rgba(0,0,0,0.5);
}

/* --- Active ON States --- */
.cell.is-on { color: #000; border-color: #fff; }
.cell.is-on[data-type="standard"] { background-color: var(--color-std); box-shadow: 0 0 15px var(--color-std); }
.cell.is-on[data-type="bishop"] { background-color: var(--color-bish); box-shadow: 0 0 15px var(--color-bish); }
.cell.is-on[data-type="bomb"] { background-color: var(--color-bomb); box-shadow: 0 0 15px var(--color-bomb); }
.cell.is-on[data-type="archer"] { background-color: var(--color-archer); box-shadow: 0 0 15px var(--color-archer); }

.cell.is-on[data-type="heavy"] {
    background-color: var(--color-heavy);
    box-shadow: 0 0 20px var(--color-heavy);
    color: #fff;
}

.cell.is-on[data-type="mirror"] {
    background-color: var(--color-mirror);
    box-shadow: 0 0 15px var(--color-mirror);
}

#message {
    margin-top: 20px;
    height: 24px;
    color: #ffcc00;
    font-weight: bold;
    text-shadow: 0 0 10px #ffcc00;
    text-align: center;
}

/* ========================================== */
/* SCREEN NAVIGATION SYSTEM */
/* ========================================== */

/* Reset body layout for screen-based navigation */
body {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

/* Screen containers */
.screen {
    display: none;
    width: 100%;
    max-width: 600px;
    min-height: 400px;
}

.screen.active {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
}

/* ========================================== */
/* HOME SCREEN */
/* ========================================== */

.home-content {
    text-align: center;
    padding: 40px;
    width: 100%;
    max-width: 650px;
}

.game-logo {
    font-size: 3.5rem;
    font-weight: bold;
    margin: 0 0 15px 0;
    letter-spacing: 8px;
    color: var(--color-std);
    text-shadow: 0 0 30px var(--color-std);
}

.how-to-play-top {
    margin-bottom: 35px;
}

.section-header {
    font-size: 1.1rem;
    color: #aaa;
    margin: 0 0 20px 0;
    text-transform: uppercase;
    letter-spacing: 2px;
    font-weight: 500;
}

/* Daily Puzzle Cards */
.difficulty-cards {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 20px;
    margin-bottom: 40px;
}

.diff-card {
    background: var(--panel-color);
    border: 2px solid #333;
    border-radius: 12px;
    padding: 30px 20px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.diff-card:hover {
    border-color: var(--color-std);
    box-shadow: 0 0 20px rgba(0, 255, 204, 0.3);
    transform: translateY(-5px);
}

.diff-name {
    font-size: 1.3rem;
    font-weight: bold;
    color: var(--color-std);
    display: block;
}

.diff-size {
    font-size: 0.9rem;
    color: #aaa;
    display: block;
}

.diff-desc {
    font-size: 0.8rem;
    color: #666;
    display: block;
}

/* Random Puzzle Buttons */
.random-puzzle-section {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.random-btn {
    background: transparent;
    border: 2px solid #444;
    border-radius: 8px;
    padding: 14px 20px;
    color: #888;
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: 500;
}

.random-btn:hover {
    background: rgba(0, 255, 204, 0.05);
    border-color: var(--color-std);
    color: var(--color-std);
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.2);
}

.random-btn:active {
    transform: scale(0.98);
}

/* ========================================== */
/* GAME SCREEN HEADER */
/* ========================================== */

#screen-game {
    max-width: 700px;
}

.game-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 15px 20px;
    background: var(--panel-color);
    border-radius: 10px;
    margin-bottom: 15px;
    border: 1px solid #333;
}

.header-center {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
}

.header-title {
    font-size: 1rem;
    color: #aaa;
}

.header-title span {
    color: var(--color-std);
    font-weight: bold;
}

.restart-btn {
    background: transparent;
    border: none;
    color: #666;
    font-size: 0.75rem;
    cursor: pointer;
    padding: 2px 6px;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.restart-btn:hover {
    color: var(--color-std);
}

.icon-btn {
    background: transparent;
    border: 1px solid #444;
    color: #aaa;
    font-size: 1.2rem;
    width: 36px;
    height: 36px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
    display: flex;
    align-items: center;
    justify-content: center;
}

.icon-btn:hover {
    background: #333;
    border-color: var(--color-std);
    color: var(--color-std);
}

/* ========================================== */
/* BUTTONS */
/* ========================================== */

.text-btn {
    background: transparent;
    border: none;
    color: #888;
    padding: 10px 20px;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.2s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.text-btn:hover {
    color: var(--color-std);
}

/* ========================================== */
/* MODALS */
/* ========================================== */

.modal {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

.modal.active {
    display: flex;
}

.modal-content {
    background: var(--panel-color);
    border: 2px solid var(--color-std);
    border-radius: 15px;
    padding: 40px;
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.8);
    position: relative;
}

.modal-large {
    max-width: 600px;
    max-height: 80vh;
    overflow-y: auto;
}

.modal-close {
    position: absolute;
    top: 15px;
    right: 15px;
    background: transparent;
    border: 1px solid #444;
    color: #aaa;
    font-size: 1.2rem;
    width: 32px;
    height: 32px;
    border-radius: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.modal-close:hover {
    background: #333;
    border-color: #ff3d00;
    color: #ff3d00;
}

/* ========================================== */
/* WIN MODAL */
/* ========================================== */

.win-rating {
    font-size: 1.8rem;
    color: var(--color-std);
    margin: 10px 0 20px 0;
    font-weight: bold;
    text-shadow: 0 0 15px var(--color-std);
}

.win-stats {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
    margin: 20px 0 30px 0;
}

.win-stat-item {
    background: #121212;
    padding: 15px;
    border-radius: 8px;
    border: 1px solid #333;
}

.win-stat-item small {
    display: block;
    color: #666;
    font-size: 0.75rem;
    text-transform: uppercase;
    margin-bottom: 5px;
}

.win-stat-item span {
    display: block;
    color: var(--color-std);
    font-size: 1.5rem;
    font-weight: bold;
}

/* ========================================== */
/* HELP MODAL */
/* ========================================== */

.tile-legend {
    text-align: left;
    margin: 20px 0;
    max-height: 400px;
    overflow-y: auto;
    list-style: none;
    padding: 0;
}

.tile-legend-item {
    padding: 10px 12px;
    margin-bottom: 6px;
    font-size: 0.85rem;
    color: #aaa;
    line-height: 1.5;
    background: #1a1a1a;
    border-radius: 6px;
    border: 1px solid #2a2a2a;
}

.tile-legend-item span {
    font-weight: bold;
    display: inline-block;
    min-width: 120px;
}

/* ========================================== */
/* HELP MODAL - NEW UNIFIED LEGEND LIST */
/* ========================================== */

.help-legend {
  margin: 18px 0 10px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.legend-hint {
  font-size: 0.78rem;
  color: #777;
  margin: 0 0 4px 2px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

/* Each row is equal-height, aligned columns */
.legend-row {
  --accent: var(--color-std);
  display: grid;
  grid-template-columns: 170px 1fr 130px;
  gap: 12px;
  align-items: center;
  padding: 12px 12px;
  border-radius: 12px;
  background: #1a1a1a;
  cursor: pointer;
  user-select: none;
  transition: all 0.18s ease;
}

.legend-row:hover {
  background: #1e1e1e;
  transform: translateY(-1px);
}

.legend-row:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* Accent per type */
.legend-row[data-type="standard"] { --accent: var(--color-std); }
.legend-row[data-type="bishop"]   { --accent: var(--color-bish); }
.legend-row[data-type="bomb"]     { --accent: var(--color-bomb); }
.legend-row[data-type="archer"]   { --accent: var(--color-archer); }
.legend-row[data-type="heavy"]    { --accent: var(--color-heavy); }
.legend-row[data-type="mirror"]   { --accent: var(--color-mirror); }
.legend-row[data-type="wall"]     { --accent: var(--color-wall); }

.legend-left {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 10px;
  align-items: center;
}

.legend-badge {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 900;
  font-size: 1.2rem;
  background: var(--accent);
  color: #000;
  box-shadow: 0 0 16px rgba(0, 0, 0, 0.45);
}

.legend-row[data-type="heavy"] .legend-badge,
.legend-row[data-type="wall"] .legend-badge {
  color: #fff;
}

.legend-name {
  font-weight: 800;
  color: #e8e8e8;
  line-height: 1.1;
}

.legend-sub {
  font-size: 0.78rem;
  color: #8a8a8a;
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.legend-desc {
  font-size: 0.88rem;
  color: #b0b0b0;
  line-height: 1.35;
}

/* Mini preview grid */
.legend-preview {
  --mini: 12px;
  display: grid;
  grid-template-columns: repeat(5, var(--mini));
  gap: 3px;
  padding: 8px;
  border-radius: 10px;
  background: #121212;
  border: 1px solid #2a2a2a;
  justify-content: center;
}

.legend-preview .mini-cell {
  width: var(--mini);
  height: var(--mini);
  border-radius: 4px;
  background: #2a2a2a;
  transition: transform 0.12s ease;
}

/* "Clicked" cell */
.legend-preview .mini-cell.is-source {
  background: var(--accent);
  outline: 2px solid #fff;
  outline-offset: -1px;
}

/* "Affected" cells */
.legend-preview .mini-cell.is-hit {
  background: var(--accent);
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 65%, transparent);
}

/* Wall cell */
.legend-preview .mini-cell.is-wall {
  background: #1a1a1a;
  border: 1px solid #333;
  box-shadow: none;
  outline: none;
}

@keyframes miniPulse {
  0%   { transform: scale(1); filter: brightness(1); }
  50%  { transform: scale(1.12); filter: brightness(1.25); }
  100% { transform: scale(1); filter: brightness(1); }
}

.legend-preview .mini-cell.flash {
  animation: miniPulse 380ms ease;
}

/* Responsive: stack on small screens */
@media (max-width: 520px) {
  .legend-row {
    grid-template-columns: 1fr;
  }
  .legend-preview {
    justify-content: flex-start;
  }
}

/* ========================================== */
/* DEV SCREEN */
/* ========================================== */

#screen-dev {
    max-width: 100%;
    width: 100%;
}

.dev-container {
    display: flex;
    gap: 30px;
    width: 100%;
    max-width: 1400px;
    padding: 20px;
    align-items: flex-start;
}

.dev-menu {
    flex: 0 0 320px;
    max-height: calc(100vh - 80px);
    overflow-y: auto;
}

.dev-game-area {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
}

.dev-stats-container {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 15px;
    font-size: 1rem;
    text-align: center;
    background: #1e1e1e;
    padding: 10px;
    border-radius: 8px;
    border: 1px solid #333;
    width: 100%;
    max-width: 500px;
    box-sizing: border-box;
}

#dev-game-grid {
    display: grid;
    grid-gap: var(--grid-gap);
    padding: 20px;
    background: #1a1a1a;
    border-radius: 15px;
    box-shadow: inset 0 0 20px #000;
}

#dev-message {
    margin-top: 10px;
    height: 24px;
    color: #ffcc00;
    font-weight: bold;
    text-shadow: 0 0 10px #ffcc00;
    text-align: center;
}

/* ========================================== */
/* RESPONSIVE */
/* ========================================== */

@media (max-width: 950px) {
    .game-logo {
        font-size: 2.5rem;
        letter-spacing: 4px;
    }

    .home-content {
        padding: 20px;
    }

    .difficulty-cards {
        grid-template-columns: 1fr;
    }

    .random-puzzle-section {
        grid-template-columns: 1fr;
    }

    :root {
        --cell-size: 45px;
    }

    /* Fix game screen alignment on mobile - start at top instead of center */
    body {
        align-items: flex-start;
        padding: 10px;
    }

    #screen-game.active {
        justify-content: flex-start;
        min-height: auto;
    }

    .screen {
        min-height: auto;
    }
}
