/* MaksimOS apps, second batch: Snake, Tetris, Calculator, Calendar, Pictures.
   Chrome uses the theme tokens from os.css. Game boards and LCDs are always
   dark, in both themes, like .mines-led and the Flappy Bird sky. */

/* --- Shared by the two arcade games ---------------------------------------- */

.snake,
.tetris {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: var(--chrome);
  user-select: none;
}
.snake-stage,
.tetris-stage {
  display: grid;
  place-items: center;
  flex: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: #1b2a4a var(--dither);
  touch-action: none;
  cursor: pointer;
}
.snake-stage:focus-visible,
.tetris-stage:focus-visible {
  outline: 2px dotted var(--accent);
  outline-offset: -2px;
}
.snake-frame,
.tetris-frame {
  position: relative;
}
.snake-canvas,
.tetris-canvas {
  display: block;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
.snake-overlay,
.tetris-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 12px;
  background: rgba(36, 37, 37, 0.62);
  color: #fff9e9;
  text-align: center;
  pointer-events: none;
}
.snake-overlay-title,
.tetris-overlay-title {
  color: #e3b95f;
  font: 400 34px/1 var(--display);
  text-shadow: 2px 2px 0 #242525;
}
.snake-overlay-hint,
.tetris-overlay-hint {
  font: 17px/1.2 var(--display);
  text-shadow: 1px 1px 0 #242525;
}
.snake-led,
.tetris-led {
  display: block;
  padding: 2px 5px;
  background: #160c0a;
  color: #ff4a2e;
  font: 22px/1 "Jersey 15", monospace;
  letter-spacing: 0.06em;
  text-align: right;
  box-shadow: inset 1px 1px var(--bevel-lo), inset -1px -1px var(--bevel-hi);
}

/* On-screen controls: touch screens and phone-sized windows only. */
.snake-pad,
.tetris-pad {
  display: none;
  flex: none;
  padding: 6px;
  gap: 4px;
  background: var(--chrome);
  border-top: 1px solid var(--border);
  touch-action: none;
}
.snake-pad-btn,
.tetris-pad-btn {
  display: grid;
  place-items: center;
  height: 46px;
  padding: 0;
  border: 0;
  background: var(--chrome);
  color: var(--text);
  box-shadow: var(--raised);
  cursor: pointer;
  fill: currentColor;
  touch-action: none;
}
.snake-pad-btn:active,
.tetris-pad-btn:active {
  background: var(--pressed);
  box-shadow: var(--sunken);
}
.snake-pad-btn:focus-visible,
.tetris-pad-btn:focus-visible {
  outline: 1px dotted var(--text);
  outline-offset: -5px;
}
.snake-pad-btn svg,
.tetris-pad-btn svg {
  width: 22px;
  height: 22px;
}
@media (max-width: 640px), (pointer: coarse) {
  .snake-pad,
  .tetris-pad {
    display: grid;
  }
}
@media (max-width: 640px) {
  /* One row of buttons on a phone, so the board keeps the height. */
  .snake .game-bar,
  .tetris .game-bar {
    flex-wrap: nowrap;
    gap: 3px;
    padding: 4px;
  }
  .snake .game-btn,
  .tetris .game-btn {
    flex: 1;
    justify-content: center;
    padding: 0 3px;
  }
  .snake .game-btn-icon,
  .tetris .game-btn-icon {
    display: none;
  }
}

/* --- Snake ------------------------------------------------------------------ */

.snake-hud {
  display: flex;
  flex: none;
  justify-content: space-between;
  padding: 5px 8px;
  border-bottom: 1px solid var(--border);
}
.snake-stat {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font: 16px/1 var(--display);
}
.snake-led {
  min-width: 50px;
}
.snake-pad {
  grid-template-columns: repeat(3, 72px);
  grid-template-areas: ". up ." "left down right";
  justify-content: center;
}
.snake-pad-btn {
  height: 42px;
}
.snake-pad-btn.is-up { grid-area: up; }
.snake-pad-btn.is-down { grid-area: down; }
.snake-pad-btn.is-left { grid-area: left; }
.snake-pad-btn.is-right { grid-area: right; }
.snake-arrow.is-down { transform: rotate(180deg); }
.snake-arrow.is-left { transform: rotate(-90deg); }
.snake-arrow.is-right { transform: rotate(90deg); }

/* --- Tetris ----------------------------------------------------------------- */

.tetris-main {
  display: flex;
  flex: 1;
  min-height: 0;
}
.tetris-side {
  display: flex;
  flex: none;
  flex-direction: column;
  gap: 6px;
  width: 96px;
  padding: 6px;
  overflow: hidden;
  border-left: 1px solid var(--border);
}
.tetris-panel {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.tetris-label {
  font: 15px/1 var(--display);
}
.tetris-next {
  display: block;
  width: 72px;
  height: 56px;
  align-self: center;
  box-shadow: 0 0 0 1px var(--bevel-hi), 0 0 0 2px var(--bevel-lo);
}
.tetris-led {
  overflow: hidden;
  font-size: 20px;
}
.tetris-pad {
  grid-template-columns: repeat(5, 1fr);
}
.tetris-arrow {
  display: block;
  width: 22px;
  height: 22px;
}
.tetris-arrow.is-down { transform: rotate(180deg); }
.tetris-arrow.is-left { transform: rotate(-90deg); }
.tetris-arrow.is-right { transform: rotate(90deg); }

/* --- Calculator ------------------------------------------------------------- */

.calc {
  display: flex;
  flex-direction: column;
  gap: 8px;
  height: 100%;
  min-height: 0;
  padding: 8px;
  background: var(--chrome);
  outline: none;
  user-select: none;
}
.calc:focus-visible .calc-lcd {
  outline: 1px dotted var(--text);
  outline-offset: 2px;
}
.calc-lcd {
  flex: none;
  padding: 6px 8px;
  background: #1c2b22;
  color: #b7e39c;
  box-shadow: var(--sunken);
  text-align: right;
}
.calc-lcd-top {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  min-height: 18px;
  color: #7fae6c;
  font: 16px/18px var(--display);
}
.calc-expr {
  flex: 1;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.calc-value {
  display: block;
  overflow: hidden;
  font: 36px/40px var(--display);
  white-space: nowrap;
}
.calc-value.is-long {
  font-size: 28px;
}
.calc-value.is-error {
  color: #ffb29e;
  font-size: 26px;
}
.calc-keys {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(5, 1fr);
  grid-auto-rows: 1fr;
  gap: 4px;
  min-height: 0;
}
.calc-key {
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 36px;
  padding: 0;
  border: 0;
  background: var(--chrome);
  color: var(--text);
  box-shadow: var(--raised);
  font: 20px/1 var(--display);
  cursor: pointer;
  fill: currentColor;
}
.calc-key svg {
  width: 22px;
  height: 14px;
}
.calc-key:active {
  background: var(--pressed);
  box-shadow: var(--sunken);
}
.calc-key:focus-visible {
  outline: 1px dotted currentColor;
  outline-offset: -5px;
}
.calc-key.is-mem,
.calc-key.is-fn {
  background: var(--bevel-mid);
}
:root[data-theme="dark"] .calc-key.is-mem,
:root[data-theme="dark"] .calc-key.is-fn {
  background: #474b48;
}
.calc-key.is-op {
  background: var(--title);
  color: var(--on-title);
}
.calc-key.is-clear {
  background: #b5523b;
  color: #fff9e9;
}
.calc-key.is-eq {
  background: var(--accent);
  color: #242525;
}
.calc-key.is-blocked {
  opacity: 0.5;
  cursor: default;
}

/* --- Calendar --------------------------------------------------------------- */

.cal {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  overflow: auto;
  background: var(--window);
}
.cal-head {
  display: flex;
  flex: none;
  align-items: center;
  gap: 4px;
  padding: 6px 8px;
  background: var(--chrome);
  border-bottom: 1px solid var(--border);
}
.cal-month {
  flex: 1;
  min-width: 0;
  margin: 0;
  font: 400 21px/1 var(--display);
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cal-nav {
  flex: none;
  width: 32px;
  height: 28px;
  padding: 0;
  border: 0;
  background: var(--chrome);
  color: var(--text);
  box-shadow: var(--raised);
  font: 14px/1 var(--display);
  cursor: pointer;
}
.cal-nav:active {
  background: var(--pressed);
  box-shadow: var(--sunken);
}
.cal-nav:focus-visible {
  outline: 1px dotted var(--text);
  outline-offset: -5px;
}
.cal-today {
  flex: none;
  min-width: 0;
  padding: 3px 10px;
}
.cal-grid {
  display: flex;
  flex: 1;
  flex-direction: column;
  gap: 2px;
  min-height: 232px;
  padding: 6px 8px;
}
.cal-row {
  display: grid;
  flex: 1;
  grid-template-columns: repeat(7, 1fr);
  gap: 2px;
}
.cal-row.is-head {
  flex: none;
}
.cal-dow {
  color: var(--muted);
  font: 15px/1.4 var(--display);
  text-align: center;
}
.cal-day {
  position: relative;
  display: grid;
  place-items: center;
  min-width: 0;
  min-height: 32px;
  padding: 0;
  border: 0;
  background: var(--chrome);
  color: var(--text);
  box-shadow: var(--raised);
  font: 18px/1 var(--display);
  cursor: pointer;
}
.cal-day.is-outside {
  background: none;
  box-shadow: none;
  color: var(--muted);
}
.cal-day.is-today {
  box-shadow: inset 0 0 0 2px var(--accent);
}
.cal-day.is-selected {
  background: var(--select);
  color: var(--select-text);
}
.cal-day:focus-visible {
  outline: 1px dotted currentColor;
  outline-offset: -5px;
}
.cal-mark {
  position: absolute;
  right: 4px;
  bottom: 4px;
  display: none;
  width: 5px;
  height: 5px;
  background: var(--accent);
  box-shadow: 1px 1px 0 var(--edge);
}
.cal-day.has-posts .cal-mark {
  display: block;
}
.cal-detail {
  flex: none;
  max-height: 40%;
  min-height: 74px;
  padding: 6px 10px 8px;
  overflow: auto;
  background: var(--chrome);
  border-top: 1px solid var(--border);
}
.cal-detail-title {
  margin: 0 0 4px;
  font: 400 17px/1.2 var(--display);
}
.cal-posts {
  margin: 0;
  padding: 0;
  list-style: none;
}
.cal-none {
  color: var(--muted);
  font-size: 13px;
}
.cal-post {
  display: block;
  width: 100%;
  padding: 2px 0;
  border: 0;
  background: none;
  color: var(--title);
  font: 13px/1.4 var(--body);
  text-align: left;
  text-decoration: underline;
  cursor: pointer;
}
:root[data-theme="dark"] .cal-post {
  color: var(--accent);
}

/* --- Pictures --------------------------------------------------------------- */

.pics {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
  background: var(--chrome);
  outline: none;
}
.pics-browse,
.pics-viewer {
  display: flex;
  flex: 1;
  flex-direction: column;
  min-height: 0;
}
.pics-tabs {
  display: flex;
  flex: none;
  padding: 7px 8px 0;
}
.pics-panel {
  flex: 1;
  min-height: 0;
  overflow: auto;
  background: var(--window);
  box-shadow: inset 1px 1px var(--bevel-hi), inset -1px -1px var(--edge), inset -2px -2px var(--bevel-lo);
}
.pics-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 8px;
  padding: 10px;
}
.pics-thumb {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
  padding: 4px;
  border: 0;
  background: none;
  color: var(--text);
  cursor: pointer;
}
.pics-thumb:hover .pics-thumb-frame {
  box-shadow: 0 0 0 2px var(--accent);
}
.pics-thumb:focus-visible {
  outline: 1px dotted var(--text);
  outline-offset: 0;
}
.pics-thumb-frame {
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  overflow: hidden;
  background: #8e918a var(--dither);
  box-shadow: 0 0 0 1px var(--border), 2px 2px 0 var(--edge);
}
.pics-thumb-frame.is-drawing,
.pics-stage:has(.is-drawing) {
  /* The checkerboard Paint uses for transparent pixels. */
  background: conic-gradient(#e4e2d8 25%, #fff9e9 0 50%, #e4e2d8 0 75%, #fff9e9 0) 0 0 / 16px 16px;
}
.pics-thumb-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.pics-thumb-frame.is-drawing img {
  object-fit: contain;
  image-rendering: pixelated;
}
.pics-thumb-missing {
  color: #fff9e9;
  font: 15px/1 var(--display);
}
.pics-thumb-name {
  overflow: hidden;
  font: 15px/1.2 var(--display);
  text-align: center;
  white-space: nowrap;
  text-overflow: ellipsis;
}
.pics-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 100%;
  padding: 24px;
  text-align: center;
}
.pics-empty p {
  margin: 0;
}
.pics-empty-title {
  font: 22px/1.1 var(--display);
}
.pics-empty-text,
.pics-note {
  color: var(--muted);
  font-size: 13px;
}
.pics-note {
  margin: 0;
  padding: 16px;
  text-align: center;
}
.pics-stage {
  display: grid;
  flex: 1;
  place-items: center;
  min-height: 0;
  overflow: hidden;
  padding: 8px;
  background: #242525 var(--dither);
}
.pics-image {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
}
.pics-image.is-drawing {
  image-rendering: pixelated;
}
.pics-missing {
  margin: 0;
  color: #fff9e9;
  font: 18px/1.2 var(--display);
}
.pics-caption {
  flex: none;
  margin: 0;
  padding: 4px 8px;
  overflow: hidden;
  border-top: 1px solid var(--border);
  font: 15px/1.2 var(--display);
  white-space: nowrap;
  text-overflow: ellipsis;
}
