/*
  CRT skin for Token Counter Toy.
  Linked after css/base.css. Styles the shared shell only:
  #app, #input, #chips, #stats, .stat, .chip, and the model <select>.

  Self-hosted fonts, SIL Open Font License 1.1:
  - Fredoka (case, stickers, controls): fonts/fredoka/OFL.txt
  - VT323 (phosphor screen text): fonts/vt323/OFL.txt
*/

@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("../fonts/fredoka/fredoka-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "Fredoka";
  font-style: normal;
  font-weight: 300 700;
  font-display: swap;
  src: url("../fonts/fredoka/fredoka-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: "VT323";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/vt323/vt323-latin-ext.woff2") format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
  font-family: "VT323";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("../fonts/vt323/vt323-latin.woff2") format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  --desk-a: #c5e6ff;
  --desk-b: #f8d4ea;
  --desk-c: #ffe6c0;
  --case: #f6e6c8;
  --case-deep: #e7cfa3;
  --case-lip: #d8bc8c;
  --case-edge: #c9a56e;
  --case-ink: #4a3218;
  --case-ink-soft: #6b4a28;
  --accent: #ffd84a;
  --accent-hot: #ffe98a;
  --accent-deep: #e0a31a;
  --sticker-pink: #ff9ec8;
  --sticker-mint: #8cf0c8;
  --screen: #0e3c39;
  --screen-glow: #1b6a63;
  --screen-deep: #0a2e2c;
  --phosphor: #e9fff8;
  --phosphor-dim: #9ddecb;
  --glow: rgba(100, 240, 200, 0.28);
  --bezel: #e8d4ae;
  --chip-ink: #2a1c10;
  --chip-0: #ffe15a;
  --chip-1: #ff9ec8;
  --chip-2: #8cf0c8;
  --chip-3: #ffb483;
  --chip-4: #c9c8ff;
  --chip-5: #fff3c4;
  --font-ui: "Fredoka", "Trebuchet MS", "Segoe UI", sans-serif;
  --font-crt: "VT323", "Courier New", ui-monospace, monospace;
  --tap: 48px;
  --radius-case: 36px;
  --radius-screen: 26px;
  color-scheme: light;
}

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

html {
  overflow-x: clip;
  max-width: 100%;
}

html,
body {
  margin: 0;
  min-height: 100%;
}

body {
  min-height: 100vh;
  font-family: var(--font-ui);
  font-weight: 500;
  font-size: 16px;
  line-height: 1.4;
  color: var(--case-ink);
  background-color: var(--desk-b);
  background-image:
    radial-gradient(rgba(255, 255, 255, 0.55) 1.1px, transparent 1.2px),
    radial-gradient(ellipse at 8% 0%, rgba(255, 255, 255, 0.75), transparent 42%),
    radial-gradient(ellipse at 100% 100%, rgba(255, 190, 214, 0.45), transparent 46%),
    linear-gradient(165deg, var(--desk-a) 0%, var(--desk-b) 48%, var(--desk-c) 100%);
  background-size: 18px 18px, auto, auto, auto;
  padding: 28px max(16px, env(safe-area-inset-right)) 48px max(16px, env(safe-area-inset-left));
}

#app {
  position: relative;
  width: min(820px, 100%);
  margin: 0 auto;
  padding: 42px 18px 52px;
  border: 3px solid #fff8ee;
  border-radius: var(--radius-case);
  background-color: var(--case);
  background-image:
    radial-gradient(circle at 34px 22px, var(--sticker-pink) 0 14px, #fff 15px, #fff 17px, transparent 18px),
    radial-gradient(circle at calc(100% - 38px) 24px, var(--accent) 0 11px, #fff 12px, #fff 14px, transparent 15px),
    radial-gradient(circle at calc(100% - 68px) 18px, var(--sticker-mint) 0 7px, transparent 8px),
    linear-gradient(180deg, #fbf1de 0%, var(--case) 38%, var(--case-deep) 100%);
  background-repeat: no-repeat;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.85),
    inset 0 -8px 0 rgba(150, 100, 40, 0.16),
    0 12px 0 var(--case-lip),
    0 22px 36px rgba(90, 55, 20, 0.26);
  min-height: 0;
}

/* Power lamp on the top bezel. */
#app::before {
  content: "";
  position: absolute;
  top: 15px;
  left: 50%;
  width: 13px;
  height: 13px;
  margin-left: -6px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 35%, #fff7c2, var(--accent) 42%, var(--accent-deep) 80%);
  box-shadow:
    0 0 8px var(--accent),
    inset 0 -1px 2px rgba(120, 70, 0, 0.45);
  pointer-events: none;
}

/* Speaker grill along the bottom lip. */
#app::after {
  content: "";
  position: absolute;
  left: 28px;
  right: 28px;
  bottom: 16px;
  height: 14px;
  background: radial-gradient(circle, var(--case-edge) 1.5px, transparent 1.7px);
  background-size: 12px 14px;
  background-repeat: repeat-x;
  pointer-events: none;
  opacity: 0.85;
}

#app header,
#app footer {
  text-align: center;
}

#app header p,
#app footer p {
  color: var(--case-ink-soft);
}

#app h1,
#app h2 {
  margin: 0 2.4rem 0.35rem;
  text-align: center;
  font-size: clamp(1.35rem, 2.4vw, 1.8rem);
  font-weight: 700;
  line-height: 1.15;
  letter-spacing: 0.01em;
  color: var(--case-ink);
  text-shadow: 0 2px 0 #fff8ee;
}

/* The glass is one piece: textarea, chips flush under it, then the stickers. */
#app main {
  display: flex;
  flex-direction: column;
  gap: 0;
  flex: 0 0 auto;
  min-width: 0;
  width: 100%;
}

label[for="input"] {
  display: block;
  margin: 0 0.35rem 0.4rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--case-ink-soft);
}

#input,
#chips {
  width: 100%;
  max-width: 100%;
  margin: 0;
  color: var(--phosphor);
  background-color: var(--screen);
  background-image:
    linear-gradient(165deg, rgba(255, 255, 255, 0.16) 0%, rgba(255, 255, 255, 0) 34%),
    radial-gradient(ellipse at 50% 42%, rgba(0, 0, 0, 0) 48%, rgba(0, 0, 0, 0.4) 100%),
    repeating-linear-gradient(
      to bottom,
      rgba(0, 0, 0, 0.16) 0 1px,
      rgba(0, 0, 0, 0) 1px 4px
    ),
    linear-gradient(180deg, var(--screen-glow) 0%, var(--screen) 56%, var(--screen-deep) 100%);
  box-shadow:
    inset 0 0 0 3px rgba(255, 225, 90, 0.4),
    inset 0 0 42px rgba(0, 0, 0, 0.32),
    inset 0 0 80px rgba(125, 255, 224, var(--phosphor-glow, 0.06)),
    0 0 18px rgba(100, 240, 200, var(--phosphor-glow, 0.12));
}

#input {
  display: block;
  min-height: 9.5rem;
  padding: 0.9rem 1rem 0.7rem;
  border: 10px solid var(--bezel);
  border-bottom: 0;
  border-radius: var(--radius-screen) var(--radius-screen) 8px 8px;
  border-color: #f4e4c6 #e4c99a var(--bezel) #e4c99a;
  resize: vertical;
  overflow-wrap: anywhere;
  caret-color: var(--accent);
  font-family: var(--font-crt);
  font-size: 1.5rem;
  font-weight: 400;
  line-height: 1.3;
  letter-spacing: 0.01em;
  text-shadow: 0 0 6px rgba(125, 255, 224, 0.35);
  color-scheme: dark;
  scrollbar-color: #1f8f84 var(--screen);
}

#input::placeholder {
  color: var(--phosphor-dim);
  opacity: 1;
}

#input::selection {
  background: rgba(255, 225, 90, 0.88);
  color: var(--chip-ink);
  text-shadow: none;
}

#chips {
  min-height: 5.75rem;
  padding: 0.7rem 0.7rem 0.85rem;
  border: 10px solid var(--bezel);
  border-top: 3px solid rgba(255, 225, 90, 0.7);
  border-radius: 8px 8px var(--radius-screen) var(--radius-screen);
  border-color: rgba(255, 225, 90, 0.7) #e4c99a #c9a56a #e4c99a;
  display: block;
  font-family: var(--font-ui);
  font-size: 1rem;
  line-height: 1.35;
  text-shadow: none;
}

#chips:empty {
  display: flex;
  align-items: center;
  justify-content: center;
}

#chips:empty::before {
  content: "tokens land here";
  color: var(--phosphor-dim);
  font-family: var(--font-crt);
  font-size: 1.35rem;
  letter-spacing: 0.04em;
}

#chips .empty {
  margin: 0;
  color: var(--phosphor-dim);
  font-family: var(--font-crt);
  font-size: 1.35rem;
  text-align: center;
}

#chips .chip {
  display: inline-flex;
  align-items: center;
  vertical-align: middle;
  max-width: 100%;
  min-width: 1.35rem;
  justify-content: center;
  min-height: 1.7em;
  margin: 0.16rem 0.14rem;
  padding: 0.12em 0.62em 0.16em;
  border: 2px solid rgba(255, 255, 255, 0.82);
  border-radius: 999px;
  background: var(--chip-0);
  color: var(--chip-ink);
  font-family: var(--font-ui);
  font-size: 0.98rem;
  font-weight: 700;
  line-height: 1.25;
  letter-spacing: 0;
  text-shadow: none;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.78),
    0 2px 0 rgba(42, 28, 16, 0.28);
}

#chips .chip.chip--0 { background-color: var(--chip-0); color: var(--chip-ink); }
#chips .chip.chip--1 { background-color: var(--chip-1); color: var(--chip-ink); }
#chips .chip.chip--2 { background-color: var(--chip-2); color: var(--chip-ink); }
#chips .chip.chip--3 { background-color: var(--chip-3); color: var(--chip-ink); }
#chips .chip.chip--4 { background-color: var(--chip-4); color: var(--chip-ink); }
#chips .chip.chip--5 { background-color: var(--chip-5); color: var(--chip-ink); }

#chips .chip.chip--empty {
  display: inline;
  min-width: 0;
  min-height: 0;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
  vertical-align: baseline;
}

#stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  align-items: center;
  gap: 0.7rem;
  margin-top: 0.95rem;
  padding: 0.75rem;
  border: 3px solid rgba(255, 248, 236, 0.85);
  border-radius: 24px;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.38), rgba(201, 165, 110, 0.2));
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.55),
    0 4px 0 rgba(180, 140, 80, 0.22);
}

#stats > * {
  min-width: 0;
}

.stat {
  flex: 1 1 7.25rem;
  min-height: 64px;
  padding: 0.4rem 0.75rem 0.45rem;
  border: 3px solid #fff8ee;
  border-radius: 18px;
  background: linear-gradient(180deg, #fffaf0 0%, #f3e1be 100%);
  box-shadow:
    inset 0 2px 0 rgba(255, 255, 255, 0.9),
    0 4px 0 #d7b57a;
  display: flex;
  flex-direction: column;
  justify-content: center;
}

.stat__label {
  display: block;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--case-ink-soft);
}

.stat__value {
  display: block;
  margin-top: 0.1rem;
  font-size: 1.55rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--case-ink);
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.stat__note {
  flex: 1 1 100%;
  margin: 0.2rem 0.35rem 0.1rem;
  font-size: 0.8rem;
  font-weight: 500;
  line-height: 1.35;
  letter-spacing: 0;
  text-align: center;
  text-transform: none;
  color: var(--case-ink-soft);
}

#stats label.stat {
  flex: 1 1 100%;
  min-height: 0;
  margin-bottom: 0.15rem;
  padding: 0.1rem 0.15rem 0.2rem;
  border: 0;
  border-radius: 0;
  background: transparent;
  box-shadow: none;
}

#stats label {
  flex: 1 1 11rem;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 0.25rem;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--case-ink-soft);
}

#stats select {
  flex: none;
  align-self: stretch;
  width: 100%;
  max-width: 100%;
  min-height: var(--tap);
  margin: 0;
  padding: 0.35rem 2.6rem 0.35rem 0.95rem;
  border: 3px solid var(--case-ink);
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0;
  text-transform: none;
  color: var(--case-ink);
  color-scheme: light;
  cursor: pointer;
  appearance: none;
  background-color: var(--accent);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 16 16'%3E%3Cpath d='M3.2 6.2 L8 11 L12.8 6.2' fill='none' stroke='%234a3218' stroke-width='2.4' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E"),
    linear-gradient(180deg, var(--accent-hot) 0%, var(--accent) 58%, #f5c431 100%);
  background-repeat: no-repeat, no-repeat;
  background-position: right 0.85rem center, 0 0;
  background-size: 16px 16px, 100% 100%;
  box-shadow: 0 4px 0 #c49220;
}

#app button,
button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--tap);
  min-width: 8rem;
  margin: 0.9rem auto 0;
  padding: 0.45rem 1.3rem;
  border: 3px solid var(--case-ink);
  border-radius: 999px;
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  color: var(--case-ink);
  background: linear-gradient(180deg, var(--accent-hot) 0%, var(--accent) 55%, #f2c12a 100%);
  box-shadow: 0 4px 0 #c49220, 0 8px 14px rgba(90, 55, 20, 0.12);
  cursor: pointer;
}

#app > button {
  display: flex;
}

#stats button {
  margin-top: 0;
  align-self: center;
}

button:hover,
#stats select:hover {
  filter: brightness(1.04);
}

button:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  filter: none;
}

#input:focus-visible,
#chips:focus-visible,
#stats select:focus-visible,
button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--case-ink);
  outline-offset: 3px;
}

a {
  color: #8a4e16;
  font-weight: 700;
}

::selection {
  background: rgba(255, 225, 90, 0.85);
  color: var(--chip-ink);
}

@property --phosphor-glow {
  syntax: "<number>";
  inherits: false;
  initial-value: 0.1;
}

@media (prefers-reduced-motion: no-preference) {
  #input,
  #chips {
    --phosphor-glow: 0.1;
    animation: crt-phosphor 8s ease-in-out infinite;
  }

  #app::before {
    animation: led-breathe 3.4s ease-in-out infinite;
  }

  #app button,
  button,
  #stats select {
    transition: transform 0.12s ease, box-shadow 0.12s ease, filter 0.12s ease;
  }

  #app button:hover,
  button:hover,
  #stats select:hover {
    transform: translateY(-1px);
  }

  #app button:active,
  button:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #c49220;
  }
}

@keyframes crt-phosphor {
  0%,
  100% {
    --phosphor-glow: 0.06;
  }

  50% {
    --phosphor-glow: 0.2;
  }
}

@keyframes led-breathe {
  0%,
  100% {
    box-shadow:
      0 0 6px var(--accent),
      inset 0 -1px 2px rgba(120, 70, 0, 0.45);
  }

  50% {
    box-shadow:
      0 0 14px var(--accent-hot),
      inset 0 -1px 2px rgba(120, 70, 0, 0.45);
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }

  #app button:hover,
  button:hover,
  #stats select:hover,
  #app button:active,
  button:active {
    transform: none;
  }
}

@media (max-width: 640px) {
  body {
    padding: 8px max(8px, env(safe-area-inset-right)) 16px max(8px, env(safe-area-inset-left));
  }

  #app {
    padding: 36px 10px 46px;
    border-radius: 24px;
    box-shadow:
      inset 0 2px 0 rgba(255, 255, 255, 0.85),
      inset 0 -6px 0 rgba(150, 100, 40, 0.16),
      0 8px 0 var(--case-lip),
      0 14px 22px rgba(90, 55, 20, 0.22);
  }

  #app h1,
  #app h2 {
    margin-right: 1.6rem;
    margin-left: 1.6rem;
  }

  #input {
    min-height: 8.5rem;
    font-size: 1.35rem;
    border-width: 8px;
    border-bottom-width: 0;
    border-radius: 18px 18px 8px 8px;
  }

  #chips {
    border-width: 8px;
    border-top-width: 3px;
    border-radius: 8px 8px 18px 18px;
    padding: 0.7rem;
  }

  #stats {
    flex-direction: column;
    align-items: stretch;
    padding: 0.65rem;
  }

  .stat,
  #stats label,
  #stats button,
  #app > button,
  #app button {
    width: 100%;
    flex: 1 1 auto;
  }

  #stats select {
    width: 100%;
    flex: none;
    font-size: 0.92rem;
  }

  .stat__value {
    font-size: 1.4rem;
  }
}

@media (forced-colors: active) {
  #app {
    border: 2px solid CanvasText;
    box-shadow: none;
    background: Canvas;
  }

  #input,
  #chips,
  .stat,
  #chips .chip,
  #stats select,
  button {
    background: Canvas;
    color: CanvasText;
    border: 1px solid CanvasText;
    box-shadow: none;
    text-shadow: none;
    filter: none;
    animation: none;
  }
}
