/*
 * EduGames - Interactive Learning Games
 * (c) 2025-2026 Prof. N. All rights reserved.
 *
 * File:    styles/core/layout.css
 * Updated: 2026-10-06 15:00
 * Purpose: The frame of every page: the sticky header, the page column, and the rows of a game page (selector,
 *          control panel + scoreboard, game area). The footer is in components/footer.css.
 *
 * One column: the header, the footer and the main boxes of every page are as wide as --page-column (tokens.css) and
 * centered; they only shrink when the window is narrower than the column. The page background shows beside them.
 */

/* the smallest width the pages are made for; a narrower window scrolls sideways */
html {
  min-width: 320px;
}

body {
  display: flex;
  flex-direction: column;
  margin: 0;
  background-color: var(--bg-app);
  transition: background-color 0.3s ease, color 0.3s ease;
}

/* ----- Header ----- */

#global-header {
  position: sticky;
  top: 0;
  z-index: 1100;
  flex-shrink: 0;
  box-sizing: border-box;
  width: 100%;
  max-width: var(--page-column);
  margin: 0 auto;
  border-radius: 0 0 var(--border-radius-md) var(--border-radius-md);
  padding: 0.3rem var(--page-gutter) calc(0.3rem + 3px);
  color: var(--color-white);
  text-align: center;
  /* a soft gradient of the theme color and a gold edge */
  background: linear-gradient(100deg,
    color-mix(in srgb, var(--color-primary) 78%, #000) 0%,
    var(--color-primary) 50%,
    color-mix(in srgb, var(--color-primary) 82%, #fff) 100%);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.25), inset 0 -3px 0 #ffc107;
}

/* home | logo and title (at the left, the subject under it) | buttons, in the page column */
.header-inner {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  box-sizing: border-box;
  width: 100%;
  max-width: var(--page-column);
  margin: 0 auto;
}

.header-left {
  display: flex;
  justify-content: flex-start;
}

.header-center {
  container-type: inline-size; /* the title sizes itself to this column (see h1 below) */
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  min-width: 0;
}

.header-right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}

.header-home,
.header-home:hover {
  padding: 0.15rem 0.35rem;
  font-size: 1.4rem;
  color: var(--color-white);
  text-decoration: none;
}

.header-title-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  max-width: 100%;
  gap: 0.55rem;
}

.header-logo {
  flex-shrink: 0;
  width: 30px;
  height: 30px;
  filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
}

/* The title stays on one line: its font gets smaller when the column is too narrow (the text is about 18 times as wide
   as its font size, and the logo takes 40 px), down to a floor; in a column too narrow even for that the logo goes.
   The icons on both sides take only what they need. */
#global-header h1 {
  min-width: 0;
  margin: 0;
  font-size: clamp(0.7rem, calc((100cqw - 40px) / 18), 1.25rem);
  font-weight: 800;
  letter-spacing: 0.03em;
  text-align: left;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

@container (max-width: 230px) {
  .header-logo {
    display: none;
  }

  #global-header h1 {
    font-size: clamp(0.7rem, calc(100cqw / 18), 1.25rem);
  }
}

.header-subtitle {
  font-size: 0.95rem;
  text-align: left;
  opacity: 0.9;
}

.header-icon-btn {
  padding: 0.5rem;
  line-height: 0;
  color: inherit;
  background: transparent;
  border: none;
  cursor: pointer;
}

.header-icon-btn svg {
  width: 1.5rem;
  height: 1.5rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

@media (max-width: 600px) {
  .header-inner {
    gap: 0.25rem;
  }

  .header-icon-btn {
    padding: 0.35rem;
  }

}

/* phones keep a small logo beside the title */
@media (max-width: 420px) {
  .header-logo {
    width: 22px;
    height: 22px;
  }
}

/* ----- The page ----- */

/* The page is as tall as its content: the footer follows it, and the page scrolls as a whole */
.app-container {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  min-height: 0;
  position: relative;
}

#app-content {
  display: flex;
  flex-direction: column;
  gap: var(--space-6);
  box-sizing: border-box;
  padding: var(--space-6) var(--page-gutter) var(--space-4);
  background-color: var(--bg-app);
}

/* every main box of every page is as wide as the column */
#app-content > * {
  width: 100%;
  max-width: var(--page-column);
  margin-left: auto;
  margin-right: auto;
}

/* the home page sits close to the header and the footer */
body[data-view="home"] #app-content {
  padding-top: var(--space-2);
  padding-bottom: 0;
}

@media (max-width: 640px) {
  #app-content {
    padding-top: var(--space-4);
  }
}

@media (max-width: 480px) {
  #app-content {
    padding-top: var(--space-3);
  }
}

/* ----- Game page ----- */

body[data-view="game"] {
  --page-column: var(--page-column-game);
}

/* The icon, name and one-line description at the top */
.game-banner {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.4rem 0.75rem;
  background: var(--bg-panel);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
}

.game-banner-icon {
  flex: none;
  width: 44px;
  height: 44px;
  object-fit: contain;
  filter: drop-shadow(0 2px 4px var(--shadow-color));
}

.game-banner-title {
  margin: 0;
  font-size: 1.05rem;
  line-height: 1.2;
}

.game-banner-text {
  margin: 0;
  font-size: 0.8rem;
  color: var(--text-secondary);
}

.top-row {
  box-sizing: border-box;
  width: 100%;
}

/* The control panel and the scoreboard share the row equally: same width, same height, together exactly as wide as the
   column. When the page is narrow they stack, still equally wide. */
.middle-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
  gap: var(--space-4);
  box-sizing: border-box;
  width: 100%;
}

.middle-row #controlPanel,
.scoreboard-container {
  min-width: 0;
}

.middle-row .control-panel {
  justify-content: center;
}

.scoreboard-container #scoreboard {
  box-sizing: border-box;
  width: 100%;
  max-width: none;
  height: 100%;
  margin: 0;
}

@media (max-width: 640px) {
  .middle-row {
    grid-template-columns: minmax(0, 1fr);
    row-gap: var(--space-4);
  }
}

.bottom-row {
  display: flex;
  flex-direction: column;
  flex-grow: 1;
  gap: var(--space-4);
  box-sizing: border-box;
  width: 100%;
  min-height: 0;
}

#game-content {
  flex-grow: 1;
  box-sizing: border-box;
  min-height: 150px;
  padding: var(--space-3);
  border: 1px solid var(--border-color);
  border-radius: var(--border-radius-md);
}

/* Messages in the game area (BaseGame.showMessage: welcome text, nothing to play, load errors) */
.game-message {
  padding: 2rem;
  text-align: center;
}

.game-message-title {
  color: var(--text-primary);
}

.game-message-text {
  color: var(--text-secondary);
}

.game-message-error {
  border: 2px solid var(--color-danger);
  background-color: var(--bg-danger);
}

.game-message-error .game-message-title {
  color: var(--text-danger);
}
