/* global styles */

:root {
  /* Chrome-only for now but this will allow smooth size transitions */
  interpolate-size: allow-keywords;

  --accent-color: #00a0d1;

  --page-bg: #222844;
  --page-surface: #1b2039;
  --page-color: #f4f6ff;

  /*
   * Tile palette. The canvas can't read CSS variables directly, so QuiltBoard
   * resolves these once via getComputedStyle — swap them here to retheme the
   * whole game. Slots follow the original's color order.
   */
  --tile-0: #1b1f33;
  --tile-1: #f5f7ff;
  --tile-2: #e5484d;
  --tile-3: #f2810c;
  --tile-4: #ffd23f;
  --tile-5: #46c26a;
  --tile-6: #00a0d1;
  --tile-7: #8b5cf6;
  --tile-8: #ec4899;
  --tile-9: #a16207;
  --tile-10: #94a3b8;
  --tile-11: #14b8a6;
  --tile-12: #84cc16;
  --tile-13: #4f46e5;
  --tile-14: #d946ef;
  --tile-15: #fb7185;

  --board-bg: #2b3350;
  --board-border: rgba(255, 255, 255, 0.28);
  /*
   * The pivot marker is a ring, not a filled disc: a translucent fill vanishes
   * against --tile-1. The dark halo is what keeps it legible on light tiles.
   */
  --board-selection: rgba(255, 255, 255, 0.95);
  --board-selection-outline: rgba(9, 12, 26, 0.8);
}

html {
  box-sizing: border-box;
}

*,
*:before,
*:after {
  box-sizing: inherit;
}

body {
  display: flex;
  flex-direction: column;
  padding: 0;
  margin: 0;
  background-color: var(--page-bg);
  color: var(--page-color);

  font-family: Futura, 'Trebuchet MS', Arial, sans-serif;
  font-style: normal;
  font-variant: normal;
}

footer,
header {
  flex: 0;
  min-height: 50px;
  height: 50px;
  display: flex;
  align-items: center;

  img {
    max-height: 40px;
    margin-right: 0.5em;
  }

  h1 {
    flex: 1;
    margin-right: 50px;
    text-align: center;
  }

  a, a:visited {
    color: var(--accent-color);

    &:focus,
    &:hover {
      color: var(--page-color);
    }
  }
}

header#main-head {
  justify-content: space-between;
  padding: 0 8px;
  border-bottom: 1px solid var(--accent-color);
}

.header-identity {
  text-decoration: none;
  color: inherit;

  h1 {
    font-family: 'Arial Black', 'Arial Bold', Gadget, sans-serif;
    font-size: 24px;
  }
}

h1,
h2,
h3,
h4 {
  font-family: 'Arial Black', 'Arial Bold', Gadget, sans-serif;
  font-variant: common-ligatures small-caps;
}

#main-head > * {
  display: flex;
  flex-direction: row;
  align-items: center;
}

#logo {
  height: 40px;
  margin: 0 10px 0 5px;
}

#main-foot {
  border-top: 1px solid var(--accent-color);
  justify-content: center;
}

main {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 80vh;
  max-width: 100vw;
  overflow: hidden;

  padding: 8px;
  overflow-y: auto;
  background-color: var(--page-surface);
}

.btn,
button,
input[type='file']::file-selector-button {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5em;
  padding: 0.25em 1em;
  border-radius: 5px;
  background: transparent;
  cursor: pointer;
  font-variant: common-ligatures small-caps;
  text-decoration: none;

  img {
    height: 2em;
    width: 2em;
    margin: 0 0.25rem;
  }

  &:disabled {
    cursor: not-allowed;

    img {
      opacity: 0.5;
    }
  }

  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    outline: var(--accent-color) auto 1px;
    background-color: #ddbfc67a;
  }
}

input[type='file'] {
  border-radius: 5px;
  border: 1px solid #ccc;
  cursor: pointer;

  &::file-selector-button {
    display: inline-flex;
  }

  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    outline: var(--accent-color) auto 1px;

    &::file-selector-button {
      background-color: #ddbfc67a;
    }
  }
}

a.btn {
  &:not(:disabled):hover,
  &:not(:disabled):focus-visible {
    text-decoration: underline;
  }
}

a:focus-visible {
  outline: var(--accent-color) auto 1px;
}

/* quilt game layout */

#game {
  position: relative;
  flex: 1 1 auto;
  min-height: 12rem;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  width: 100%;
  height: 100%;
  max-width: 34rem;
}

#banner {
  position: absolute;
  inset-inline: 0;
  top: 50%;
  translate: 0 -50%;
  margin: 0;
  padding: 0.6em 1em;
  text-align: center;
  font-family: 'Arial Black', 'Arial Bold', Gadget, sans-serif;
  font-variant: common-ligatures small-caps;
  font-size: clamp(1.25rem, 6vw, 2rem);
  color: var(--page-color);
  background-color: color-mix(in srgb, var(--accent-color) 82%, transparent);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
  pointer-events: none;
}

#hud {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.5rem 0.25rem 0;
}

#levelLabel {
  margin: 0;
  font-variant: common-ligatures small-caps;
  letter-spacing: 0.06em;
}

#goal {
  display: flex;
  align-items: center;
  gap: 0.6rem;

  h3 {
    margin: 0;
    font-size: 0.8rem;
    letter-spacing: 0.1em;
    opacity: 0.75;
  }
}

#preview {
  width: 3.5rem;
  height: 3.5rem;
}

#controls {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 0 calc(0.5rem + env(safe-area-inset-bottom, 0px));
}

#pad {
  display: grid;
  grid-template-columns: repeat(3, 2.75rem);
  grid-template-rows: repeat(2, 2.75rem);
  gap: 0.35rem;

  button {
    padding: 0;
    font-size: 1.2rem;
    color: var(--page-color);
    border: 1px solid var(--board-border);
    background-color: color-mix(in srgb, var(--page-color) 8%, transparent);
  }
}

#btnShiftUp {
  grid-area: 1 / 2;
}
#btnShiftLeft {
  grid-area: 2 / 1;
}
#btnShiftDown {
  grid-area: 2 / 2;
}
#btnShiftRight {
  grid-area: 2 / 3;
}

#btnHelp,
#btnRestart,
#btnShuffle {
  color: var(--page-color);
  border: 1px solid var(--board-border);
}

/* util classes */

.u-hidden {
  display: none !important;
}

.u-flex {
  display: flex;
}

.u-flex-column {
  flex-direction: column;
}

.u-flex-1 {
  flex: 1;
}

.u-left {
  text-align: left;
}

.u-center {
  text-align: center;
}

.u-fill-width {
  width: -webkit-fill-available;
  width: 100%;
}

.u-fill-height {
  height: -webkit-fill-available;
  height: 100vh;
}

.u-stretch-height {
  height: -webkit-fill-available;
  height: 100%;
  flex: 1;
}

/* background scroll fix for dialogs */
dialog {
  overscroll-behavior: contain;
}

dialog::backdrop {
  overflow: hidden;
  overscroll-behavior: contain;
}

/* responsive design tweaks (breakpoints adopted from Bootstrap) */

/* Small devices (e.g. phones, 575px and under) */
@media (max-width: 575px) {
  header > img {
    display: none;
  }
}

/* Small devices (landscape phones, 576px and up) */
@media (min-width: 576px) {
  header > img {
    display: none;
  }
}

/* Medium devices (tablets, 768px and up) */
@media (min-width: 768px) {
  header > img {
    display: block;
  }
}

/* Large devices (desktops, 992px and up) */
@media (min-width: 992px) {
  header > img {
    display: block;
  }
}

/* web component placeholders */
update-notification {
  display: none;
  --update-notification-bg: linear-gradient(135deg, #7a7a7a 0%, #3a3a3a 50%, #5a5a5a 100%);
  --update-notification-color: white;
  --update-notification-border: transparent;
  --update-notification-btn-bg: white;
  --update-notification-btn-color: #5a5a5a;
  --update-notification-btn-hover: #f0f0f0;
}

/* view transitions */

@view-transition {
  navigation: auto;
  types: slide, forwards;
}
