:root {
  color-scheme: dark;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #0e1118;
  color: #f8fafc;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
}

body {
  min-height: 100dvh;
  background:
    linear-gradient(180deg, rgba(21, 29, 45, 0.98), rgba(7, 10, 16, 1)),
    #0e1118;
}

.app-shell {
  min-height: 100dvh;
}

.game-page {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  width: 100%;
  min-height: 100dvh;
  padding: max(12px, env(safe-area-inset-top)) max(12px, env(safe-area-inset-right))
    max(12px, env(safe-area-inset-bottom)) max(12px, env(safe-area-inset-left));
  gap: 10px;
}

.game-header {
  display: flex;
  align-items: end;
  justify-content: space-between;
  min-width: 0;
  gap: 12px;
}

.game-kicker {
  margin: 0 0 2px;
  color: #7dd3fc;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: uppercase;
}

.game-header h1 {
  margin: 0;
  overflow: hidden;
  color: #f8fafc;
  font-size: clamp(1.25rem, 5vw, 2rem);
  line-height: 1.1;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-subtitle {
  display: none;
  margin: 0;
  max-width: 42%;
  overflow: hidden;
  color: #cbd5e1;
  font-size: 0.875rem;
  line-height: 1.3;
  text-align: right;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.game-stage {
  position: relative;
  width: 100%;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 1px solid rgba(148, 163, 184, 0.22);
  border-radius: 8px;
  background: #020617;
}

.game-frame {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: #020617;
}

.game-controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
  padding-bottom: env(safe-area-inset-bottom);
}

.game-control,
.icon-button {
  border: 1px solid rgba(148, 163, 184, 0.26);
  border-radius: 8px;
  background: rgba(15, 23, 42, 0.92);
  color: #f8fafc;
  cursor: pointer;
  font: inherit;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: 0;
  touch-action: manipulation;
}

.game-control {
  display: grid;
  min-height: 38px;
  padding: 0 8px;
  place-items: center;
}

.game-control span {
  display: block;
  font-size: 1.05rem;
  line-height: 1;
}

.game-control:disabled {
  cursor: default;
  opacity: 0.42;
}

.game-modal[hidden] {
  display: none;
}

.game-modal {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: grid;
  align-items: end;
  padding: 14px;
}

.game-modal__backdrop {
  position: absolute;
  inset: 0;
  background: rgba(2, 6, 23, 0.72);
}

.game-modal__panel {
  position: relative;
  z-index: 1;
  width: min(100%, 560px);
  margin: 0 auto;
  padding: 18px;
  border: 1px solid rgba(148, 163, 184, 0.24);
  border-radius: 8px;
  background: #0f172a;
  box-shadow: 0 22px 80px rgba(0, 0, 0, 0.42);
}

.game-modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.game-modal__header h2 {
  margin: 0;
  overflow-wrap: anywhere;
  font-size: 1.2rem;
  line-height: 1.2;
}

.icon-button {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  place-items: center;
  padding: 0;
  font-size: 1.35rem;
}

.game-modal__author {
  margin: 8px 0 0;
  color: #7dd3fc;
  font-size: 0.875rem;
  font-weight: 700;
}

.game-modal__description {
  margin: 14px 0 0;
  color: #dbeafe;
  font-size: 0.95rem;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.game-stage--loading,
.game-stage--error {
  display: grid;
  place-items: center;
  padding: 24px;
  color: #cbd5e1;
  text-align: center;
}

@media (min-width: 720px) {
  .game-page {
    max-width: 980px;
    margin: 0 auto;
    padding: 20px;
    gap: 16px;
  }

  .game-subtitle {
    display: block;
  }

  .game-controls {
    max-width: 520px;
    width: 100%;
    justify-self: center;
  }

  .game-modal {
    align-items: center;
  }
}

@media (orientation: landscape) {
  html body .game-page {
    grid-template-columns: minmax(0, 1fr) 42px;
    grid-template-rows: minmax(0, 1fr);
    grid-template-areas:
      "stage controls";
    max-width: none;
    padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    gap: 8px;
  }

  html body .game-header {
    display: none;
    grid-area: header;
    min-height: 24px;
  }

  html body .game-kicker,
  html body .game-subtitle {
    display: none;
  }

  html body .game-header h1 {
    max-width: 100%;
    font-size: 0.95rem;
    line-height: 1.1;
  }

  html body .game-stage {
    grid-area: stage;
  }

  html body .game-controls {
    grid-area: controls;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(3, minmax(0, 1fr));
    width: 42px;
    max-width: none;
    height: 100%;
    padding-bottom: 0;
  }

  html body .game-control {
    min-width: 0;
    min-height: 0;
    padding: 0;
  }

  html body .game-control span {
    font-size: 1.05rem;
  }
}

html.is-landscape-ui body .game-page,
  body.is-landscape-ui .game-page {
  grid-template-columns: minmax(0, 1fr) 42px;
  grid-template-rows: minmax(0, 1fr);
  grid-template-areas:
    "stage controls";
  max-width: none;
  padding: max(8px, env(safe-area-inset-top)) max(8px, env(safe-area-inset-right))
    max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
  gap: 8px;
}

html.is-landscape-ui body .game-header,
body.is-landscape-ui .game-header {
  display: none;
  grid-area: header;
  min-height: 24px;
}

html.is-landscape-ui body .game-kicker,
html.is-landscape-ui body .game-subtitle,
body.is-landscape-ui .game-kicker,
body.is-landscape-ui .game-subtitle {
  display: none;
}

html.is-landscape-ui body .game-header h1,
body.is-landscape-ui .game-header h1 {
  max-width: 100%;
  font-size: 0.95rem;
  line-height: 1.1;
}

html.is-landscape-ui body .game-stage,
body.is-landscape-ui .game-stage {
  grid-area: stage;
}

html.is-landscape-ui body .game-controls,
body.is-landscape-ui .game-controls {
  grid-area: controls;
  grid-template-columns: 1fr;
  grid-template-rows: repeat(3, minmax(0, 1fr));
  width: 42px;
  max-width: none;
  height: 100%;
  padding-bottom: 0;
}

html.is-landscape-ui body .game-control,
body.is-landscape-ui .game-control {
  min-width: 0;
  min-height: 0;
  padding: 0;
}

html.is-landscape-ui body .game-control span,
body.is-landscape-ui .game-control span {
  font-size: 1.05rem;
}
