* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --btn-accent: #16a085;
  --btn-danger: #e74c3c;
  --btn-transition: 320ms;

  --color-bg-outer: #111;
  --color-bg-inner: #333;
  --color-panel: #ffffff;
  --color-surface: #1a1a1a;
  --color-surface-2: #161616;
  --color-border: rgba(210, 210, 210, 0.127);
  --color-food: #4873ff;
  --color-snake: #d7d7d7;
  --color-history-head: #858dff;
  --color-muted: #aaaaaa;

  --radius-1: 2px;
  --radius-2: 4px;
  --shadow-1: 0 0 1px 2px rgba(0, 0, 0, 0.3);
  --shadow-2: 0 0 2px 3px rgba(0, 0, 0, 0.3);

  --grid-width-sm: 315px;
  --grid-width-md: 420px;
  --cell-size-sm: 15px;
  --cell-size-md: 20px;
  --status-height: 30px;
  --space-page-bottom-gap: 24px;
}

body {
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  align-items: center;
  min-height: 100vh;
  font-family: 'Inter', sans-serif;
  background: radial-gradient(var(--color-bg-inner), var(--color-bg-outer));
  position: relative;
  text-align: center;
  padding-bottom: var(--space-page-bottom-gap);
}


.page--history {
  justify-content: flex-start;
}

.page-header {
  text-align: center;
  font-size: 32px;
  letter-spacing: 10px;
  padding: 20px 10px;
  color: white;
}


.btn {
  display: inline-block;
  padding: 10px 20px;
  font-size: 20px;
  border-radius: var(--radius-1);
  background-color: transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background-color var(--btn-transition) ease,
    color var(--btn-transition) ease, border-color var(--btn-transition) ease;
}
.btn--accent {
  color: var(--btn-accent);
  border: 1px solid var(--btn-accent);
}
.btn--accent:hover {
  background-color: var(--btn-accent);
  color: white;
}
.btn--danger {
  color: var(--btn-danger);
  border: 1px solid var(--btn-danger);
}
.btn--danger:hover {
  background-color: var(--btn-danger);
  color: white;
}
.btn--floating {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 1000;
}


.game__grid {
  width: var(--grid-width-sm);
  height: calc(var(--grid-width-sm) + var(--status-height));
  margin: auto;
  display: flex;
  flex-direction: row;
  justify-content: flex-start;
  flex-wrap: wrap;
  box-shadow: var(--shadow-1);
}
@media only screen and (min-width: 768px) {
  .game__grid {
    width: var(--grid-width-md);
    height: calc(var(--grid-width-md) + var(--status-height));
  }
}

.game__cell {
  background: #232323;
  border: solid 1px var(--color-border);
  width: var(--cell-size-sm);
  height: var(--cell-size-sm);
}
@media only screen and (min-width: 768px) {
  .game__cell {
    width: var(--cell-size-md);
    height: var(--cell-size-md);
  }
}
.game__cell--food {
  background: var(--color-food);
}
.game__cell--snake {
  background: var(--color-snake);
}

.game__status {
  background: var(--color-panel);
  color: var(--btn-accent);
  border: 1px solid var(--btn-accent);
  width: var(--grid-width-sm);
  height: var(--status-height);
}
@media only screen and (min-width: 768px) {
  .game__status {
    width: var(--grid-width-md);
  }
}
.game__score {
  float: right;
  padding: 0 10px;
  line-height: var(--status-height);
  font-size: 20px;
}

.hidden {
  display: none !important;
}

.modal {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: fixed;
  top: 0;
  left: 0;
  height: 100%;
  width: 100%;
  background: rgba(0, 0, 0, 0.5);
  text-align: center;
  opacity: 1;
  transition: opacity var(--btn-transition) ease;
  will-change: opacity;
}

.modal--opening {
  opacity: 0;
}
.modal--opening .modal__panel {
  transform: scale(0.96);
  opacity: 0;
}
.modal__panel {
  background: var(--color-panel);
  padding: 60px;
  box-shadow: var(--shadow-2);
  border-radius: var(--radius-1);
  opacity: 1;
  transform: scale(1);
  transition: opacity var(--btn-transition) ease, transform var(--btn-transition) ease;
}

.modal--closing {
  opacity: 0;
}
.modal--closing .modal__panel {
  transform: scale(0.96);
  opacity: 0;
}

.history {
  width: var(--grid-width-sm);
  margin: 20px auto 40px;
  background: var(--color-surface);
  color: var(--color-snake);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-2);
  box-shadow: var(--shadow-1);
  overflow: hidden;
}
@media only screen and (min-width: 768px) {
  .history {
    width: var(--grid-width-md);
  }
}
.history__actions {
  position: fixed;
  top: 12px;
  right: 12px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  z-index: 1000;
}

@media only screen and (max-width: 1024px) {
  .history__actions {
    position: static;
    top: auto;
    right: auto;
    z-index: auto;
    justify-content: center;
    margin: 8px 0 0;
  }
}
.history__empty {
  color: var(--color-muted);
  padding: 16px;
  text-align: center;
}
.history__table {
  width: 100%;
  border-collapse: collapse;
}
.history__head th {
  font-weight: 600;
  color: var(--color-history-head);
  padding: 10px 12px;
  background: var(--color-surface-2);
}
.history__body td {
  padding: 10px 12px;
  border-top: 1px solid var(--color-border);
}
.history__table tbody tr {
  transition: background-color var(--btn-transition) ease;
}
.history__table tbody tr:hover {
  background: #2a2a2a;
}

#clearHistory {
  color: var(--btn-danger);
  border-color: var(--btn-danger);
}
#clearHistory:hover {
  background-color: var(--btn-danger);
  color: white;
}
