/*
  LEARN:
  CSS is the "presentation" layer. It controls layout, spacing, color, fonts,
  and other visual details.

  In this project the HTML gives us named areas, like .game-shell and
  .character-card. This CSS file tells the browser how those areas should look.

  TRY:
  Change --page-background from #050505 to #1a1a1a and refresh the page.
  You will see how a single value can affect many parts of the page.
*/
:root {
  --page-background: #050505;
  --panel-background: #090909;
  --panel-text: #f7f7f7;
  --muted-text: #b8b8b8;
  --line-color: #f7f7f7;
  --shadow-color: #333333;
  --pixel-yellow: #ffd84d;
  --pixel-red: #ff3b30;
  --pixel-green: #39ff88;
  --player-blue: #2f7dff;
  --health-red: #d81f1f;
  --chance-black: #000000;
  --enemy-red: #ff3b30;
  --focus-green: #39ff88;
  --warning-gold: #ffd84d;
}

/*
  LEARN:
  The * selector means "every element."

  box-sizing: border-box makes sizing easier to reason about. It means that
  when we set a width, padding and borders are counted inside that width.
*/
* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.035) 1px, transparent 1px),
    var(--page-background);
  background-size: 16px 16px;
  color: #ffffff;
  font-family: "Press Start 2P", "Pixelify Sans", "VT323", "Lucida Console",
    "Courier New", monospace;
  image-rendering: pixelated;
  text-rendering: geometricPrecision;
}

button {
  font: inherit;
}

/*
  LEARN:
  .game-shell is the outer wrapper for the app.

  max-width keeps the game from stretching too wide on large screens.
  margin: 0 auto centers it horizontally.
*/
.game-shell {
  width: min(1180px, calc(100% - 32px));
  margin: 0 auto;
  padding: 24px 0 40px;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 16px;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--pixel-yellow);
  font-size: 0.8rem;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 4vw, 3rem);
  color: #ffffff;
  text-shadow: 3px 3px 0 var(--pixel-red);
}

.secondary-button,
.move-button,
.continue-button {
  border: 2px solid #ffffff;
  border-radius: 0;
  background: #111111;
  color: #ffffff;
  cursor: pointer;
  font-weight: 700;
  box-shadow: 4px 4px 0 var(--shadow-color);
  text-transform: uppercase;
}

.secondary-button {
  padding: 10px 14px;
}

.secondary-button:hover,
.move-button:hover,
.continue-button:hover {
  background: #1f1f1f;
  border-color: var(--pixel-yellow);
  color: var(--pixel-yellow);
}

.secondary-button[aria-pressed="true"] {
  background: var(--pixel-yellow);
  border-color: var(--pixel-yellow);
  color: #050505;
}

/*
  LEARN:
  Disabled buttons are still visible, but the player cannot click them.
  JavaScript adds disabled when an action is not currently legal.
*/
button:disabled {
  cursor: not-allowed;
  opacity: 0.42;
  box-shadow: none;
  pointer-events: none;
}

.status-panel,
.log-panel {
  background: var(--panel-background);
  color: var(--panel-text);
  border: 2px solid var(--line-color);
  border-radius: 0;
  padding: 16px;
  box-shadow: 6px 6px 0 var(--shadow-color);
}

.status-panel {
  margin: 22px 0 24px;
  border-width: 3px;
  padding: 18px 22px;
  text-align: center;
}

.status-panel h2,
.log-panel h2 {
  margin-bottom: 8px;
  font-size: 1.1rem;
  color: var(--pixel-yellow);
}

.status-panel h2 {
  font-size: 1.25rem;
  text-shadow: 2px 2px 0 #4d0000;
}

.status-panel p {
  max-width: 820px;
  margin-left: auto;
  margin-right: auto;
  margin-bottom: 0;
  color: #ffffff;
  font-size: 1rem;
  line-height: 1.55;
}

.status-actions {
  display: flex;
  justify-content: center;
  min-height: 44px;
  margin-top: 14px;
}

.status-actions:empty {
  display: none;
}

.mobile-battle-summary {
  display: none;
}

.summary-item:disabled {
  cursor: default;
  opacity: 1;
  box-shadow: 3px 3px 0 #303030;
  pointer-events: none;
}

.continue-button {
  min-width: 180px;
  padding: 12px 18px;
  background: var(--pixel-yellow);
  border-color: var(--pixel-yellow);
  color: #050505;
  text-align: center;
}

.continue-button:hover {
  background: #050505;
  color: var(--pixel-yellow);
}

.battlefield {
  margin: 18px 0;
}

.team-label {
  margin: 16px 0 8px;
  color: var(--pixel-yellow);
  font-size: 0.85rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
  text-shadow: 2px 2px 0 #4d0000;
}

/*
  LEARN:
  display: grid lets us arrange the three characters in a row.

  repeat(3, 1fr) means:
  "Make 3 columns, and let each column take an equal share of the space."

  TRY:
  Change repeat(3, 1fr) to repeat(2, 1fr). You will see the cards wrap into
  two columns instead of three.
*/
.character-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.boss-grid {
  grid-template-columns: minmax(260px, 420px);
  justify-content: center;
}

.character-card {
  display: flex;
  flex-direction: column;
  min-height: 268px;
  background: var(--panel-background);
  color: var(--panel-text);
  border: 3px solid #ffffff;
  border-radius: 0;
  padding: 14px;
  box-shadow: 6px 6px 0 var(--shadow-color);
}

.character-card.is-selected {
  border-color: var(--pixel-yellow);
}

.character-card.is-active {
  outline: 4px solid var(--pixel-yellow);
  outline-offset: 2px;
  box-shadow: 6px 6px 0 #5d4300;
}

.character-card.is-selectable {
  border-color: var(--pixel-green);
  cursor: pointer;
  outline: 4px solid var(--pixel-green);
  outline-offset: 2px;
  box-shadow: 6px 6px 0 #06421d;
}

.character-card.is-selectable:hover {
  background: #111111;
  border-color: var(--pixel-yellow);
  outline-color: var(--pixel-yellow);
}

.character-card.is-defeated {
  opacity: 0.55;
  filter: grayscale(1);
}

.character-card h3 {
  margin: 0 0 8px;
  font-size: 1.2rem;
  color: #ffffff;
  text-shadow: 2px 2px 0 var(--pixel-red);
}

.card-status {
  min-height: 42px;
  margin-bottom: 10px;
  color: var(--muted-text);
  line-height: 1.35;
}

/*
  LEARN:
  These are simple visual dice counters.

  The red counter is health. The blue counter is action points for players.
  They are not real 3D dice yet, but they give us a clear game readout.

  The black counter is the new chance die. It shows the d20 roll used by enemy
  attacks and player attack success checks.
*/
.dice-row {
  display: flex;
  flex-wrap: nowrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}

.die-group {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.die {
  display: grid;
  place-items: center;
  width: 46px;
  height: 46px;
  border: 2px solid #ffffff;
  border-radius: 0;
  color: #ffffff;
  font-size: 1.15rem;
  font-weight: 800;
  box-shadow: 3px 3px 0 #303030;
  transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.red-die {
  background: var(--health-red);
  color: #ffffff;
}

.blue-die {
  background: var(--player-blue);
  color: #ffffff;
}

.black-die {
  background: var(--chance-black);
  border: 2px solid #ffffff;
  color: #ffffff;
}

.die.is-rolling {
  animation: chance-die-pulse 0.28s ease-in-out infinite alternate;
  box-shadow: 0 0 0 3px var(--pixel-yellow), 4px 4px 0 #5d4300;
}

@keyframes chance-die-pulse {
  from {
    transform: translateY(0) scale(1);
  }

  to {
    transform: translateY(-2px) scale(1.08);
  }
}

.stat-label {
  color: var(--pixel-yellow);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.roll-note {
  min-height: 28px;
  margin: 0;
  border: 2px solid #ffffff;
  border-radius: 0;
  padding: 6px 8px;
  background: #111111;
  color: #ffffff;
  font-size: 0.82rem;
  font-weight: 800;
  line-height: 1.15;
  box-shadow: 3px 3px 0 #303030;
}

.roll-note-player {
  margin-bottom: 12px;
}

.roll-note-enemy {
  margin-bottom: 12px;
}

.roll-note.is-empty {
  visibility: hidden;
}

.roll-note.is-info {
  border-color: var(--pixel-yellow);
  color: var(--pixel-yellow);
}

.roll-note.is-success {
  border-color: var(--pixel-green);
  background: #06130a;
  color: var(--pixel-green);
}

.roll-note.is-failure {
  border-color: var(--pixel-red);
  background: #190707;
  color: var(--pixel-red);
}

.roll-note.is-warning {
  border-color: var(--warning-gold);
  background: #1c1703;
  color: var(--warning-gold);
}

.move-list {
  display: grid;
  gap: 8px;
  margin-top: auto;
}

.enemy-roll-table {
  display: grid;
  gap: 6px;
  margin-top: auto;
  border: 2px solid #ffffff;
  padding: 8px;
  background: #050505;
  box-shadow: 3px 3px 0 #303030;
}

.roll-table-title {
  margin: 0 0 2px;
  color: var(--pixel-yellow);
  font-size: 0.72rem;
  text-transform: uppercase;
}

.roll-table-row {
  display: grid;
  grid-template-columns: 54px minmax(0, 1fr) 68px;
  gap: 6px;
  align-items: center;
  font-size: 0.68rem;
  line-height: 1.25;
}

.roll-range {
  color: var(--pixel-yellow);
}

.roll-name {
  color: #ffffff;
  overflow-wrap: anywhere;
}

.roll-damage {
  color: var(--pixel-red);
  text-align: right;
}

.roll-table-row.is-special .roll-name,
.roll-table-row.is-special .roll-damage {
  color: var(--pixel-red);
}

.move-button {
  width: 100%;
  padding: 10px;
  text-align: left;
}

.button-title {
  display: block;
}

.button-detail {
  display: block;
  margin-top: 2px;
  color: #cfcfcf;
  font-size: 0.82rem;
  font-weight: 400;
  text-transform: none;
}

.log-panel ol {
  display: grid;
  gap: 8px;
  margin: 0;
  padding-left: 22px;
}

.log-panel li {
  line-height: 1.4;
  color: #ffffff;
}

.log-panel li::marker {
  color: var(--pixel-red);
}

/*
  LEARN:
  A media query applies CSS only when a condition is true.
  This one runs on smaller screens, where three columns would feel cramped.
*/
@media (max-width: 800px) {
  body {
    background-size: 12px 12px;
  }

  .game-shell {
    width: min(100% - 16px, 680px);
    padding: 12px 0 28px;
  }

  .game-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 10px;
  }

  h1 {
    font-size: 1.5rem;
    line-height: 1.2;
    text-shadow: 2px 2px 0 var(--pixel-red);
  }

  .header-actions {
    width: 100%;
  }

  .secondary-button {
    width: 100%;
  }

  .battlefield {
    display: flex;
    flex-direction: column;
    gap: 8px;
    margin: 10px 0 14px;
  }

  .status-panel {
    order: -3;
    position: sticky;
    top: 0;
    z-index: 20;
    margin: 0 0 10px;
    padding: 12px;
    box-shadow: 4px 4px 0 var(--shadow-color);
  }

  .status-panel h2 {
    margin-bottom: 6px;
    font-size: 0.92rem;
    line-height: 1.25;
  }

  .status-panel p {
    font-size: 0.72rem;
    line-height: 1.45;
  }

  .status-actions {
    min-height: 38px;
    margin-top: 10px;
  }

  .continue-button {
    min-width: 150px;
    padding: 10px 14px;
    font-size: 0.72rem;
  }

  .mobile-battle-summary {
    display: grid;
    gap: 8px;
    margin-top: 10px;
    text-align: left;
  }

  .summary-team {
    display: grid;
    gap: 5px;
  }

  .summary-team-label {
    margin: 0;
    color: var(--pixel-yellow);
    font-size: 0.58rem;
    text-transform: uppercase;
  }

  .summary-list {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
  }

  .summary-item {
    min-width: 0;
    min-height: 48px;
    border: 2px solid #ffffff;
    border-radius: 0;
    padding: 6px;
    background: #050505;
    color: #ffffff;
    text-align: left;
    box-shadow: 3px 3px 0 #303030;
  }

  .summary-item.is-active {
    border-color: var(--pixel-yellow);
    box-shadow: 3px 3px 0 #5d4300;
  }

  .summary-item.is-selectable {
    border-color: var(--pixel-green);
    color: var(--pixel-green);
    cursor: pointer;
    outline: 2px solid var(--pixel-green);
    outline-offset: 1px;
    pointer-events: auto;
  }

  .summary-item.is-result {
    border-color: var(--pixel-yellow);
    color: var(--pixel-yellow);
  }

  .summary-item.is-defeated {
    opacity: 0.48;
    filter: grayscale(1);
  }

  .summary-name {
    display: block;
    overflow: hidden;
    color: inherit;
    font-size: 0.56rem;
    line-height: 1.25;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .summary-stats {
    display: grid;
    gap: 2px;
    margin-top: 5px;
    color: #ffffff;
    font-size: 0.52rem;
    line-height: 1.25;
  }

  .team-label {
    display: none;
  }

  .character-grid {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .boss-grid {
    grid-template-columns: 1fr;
  }

  .character-card {
    min-height: 0;
    padding: 10px;
    box-shadow: 4px 4px 0 var(--shadow-color);
  }

  .character-card:not(.is-active):not(.is-result) {
    display: none;
  }

  .character-card h3 {
    margin-bottom: 6px;
    font-size: 0.92rem;
    line-height: 1.25;
  }

  .card-status {
    min-height: 0;
    margin-bottom: 8px;
    font-size: 0.68rem;
  }

  .dice-row {
    justify-content: flex-start;
    gap: 8px;
    margin-bottom: 8px;
  }

  .die-group {
    gap: 4px;
  }

  .die {
    width: 36px;
    height: 36px;
    font-size: 0.86rem;
    box-shadow: 2px 2px 0 #303030;
  }

  .stat-label {
    font-size: 0.56rem;
  }

  .roll-note {
    min-height: 24px;
    margin-bottom: 8px;
    padding: 5px 6px;
    font-size: 0.62rem;
  }

  .move-list {
    gap: 6px;
  }

  .move-button {
    padding: 8px;
    font-size: 0.66rem;
  }

  .button-detail {
    font-size: 0.62rem;
  }

  .enemy-roll-table {
    gap: 5px;
    padding: 7px;
  }

  .roll-table-title {
    font-size: 0.6rem;
  }

  .roll-table-row {
    grid-template-columns: 44px minmax(0, 1fr) 54px;
    gap: 5px;
    font-size: 0.56rem;
  }

  .log-panel {
    padding: 12px;
  }

  .log-panel h2 {
    font-size: 0.86rem;
  }

  .log-panel li {
    font-size: 0.68rem;
  }
}
