:root {
  --ink: #2b2550;
  --ink-soft: #6b6890;
  --paper: #ffffff;
  --panel: #ffffff;
  --sky-1: #bfe6ff;
  --sky-2: #e9f6ff;
  --sky-3: #fff4e3;
  --key: #3aa0e8;
  --key-d: #1f7cc2;

  --tap: 72px;
  --r: 22px;
  --ui-font: "Fredoka", "Segoe UI Rounded", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 12px 16px 0;
  background: linear-gradient(170deg, var(--sky-1) 0%, var(--sky-2) 45%, var(--sky-3) 100%);
  color: var(--ink);
  font-family: var(--ui-font);
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button { font-family: inherit; color: inherit; cursor: pointer; touch-action: manipulation; border: none; background: none; padding: 0; }
svg { width: 100%; height: 100%; fill: currentColor; }
svg .stroke { fill: none; stroke: currentColor; stroke-width: 5; stroke-linecap: round; stroke-linejoin: round; }
svg .paper { fill: #fff; stroke: currentColor; stroke-width: 3.5; stroke-linejoin: round; }
.cap { display: block; font-size: 15px; font-weight: 600; line-height: 1; letter-spacing: .01em; }

/* ---------- Floating letters in the background ---------- */
.sky { position: fixed; inset: 0; pointer-events: none; z-index: 0; overflow: hidden; }
.float {
  position: absolute;
  font-family: "Luckiest Guy", var(--ui-font);
  font-size: 90px;
  opacity: .16;
  animation: drift 14s ease-in-out infinite alternate;
}
.f1 { left: 2%; top: 30%; color: #ff5d8f; }
.f2 { left: 90%; top: 22%; color: #3aa0e8; animation-delay: -3s; font-size: 120px; }
.f3 { left: 6%; top: 74%; color: #ffa41b; animation-delay: -6s; }
.f4 { left: 93%; top: 66%; color: #9b6cf0; animation-delay: -2s; }
.f5 { left: 48%; top: 88%; color: #2ec27e; animation-delay: -8s; font-size: 70px; }
.f6 { left: 80%; top: 90%; color: #ff5d8f; animation-delay: -5s; font-size: 50px; }
.f7 { left: 15%; top: 50%; color: #22b8cf; animation-delay: -9s; font-size: 70px; }
.f8 { left: 85%; top: 44%; color: #ffa41b; animation-delay: -1s; font-size: 60px; }
@keyframes drift { from { transform: translateY(0) rotate(-8deg); } to { transform: translateY(-24px) rotate(8deg); } }

/* ---------- Top bar ---------- */
.topbar {
  position: relative;
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 12px 8px 14px;
  background: var(--panel);
  border-radius: 28px;
  box-shadow: 0 6px 0 #9fcbe866, 0 14px 30px #3a6c9a22;
}
.logo { display: flex; align-items: center; gap: 10px; }
.logo-mark {
  width: 58px; height: 58px; padding: 9px;
  border-radius: 18px;
  background: linear-gradient(145deg, #5ab8ff, #3a7ff0);
  box-shadow: inset 0 -5px 0 #0002, 0 4px 0 #2a63c4;
}
.logo-text { font-size: 34px; font-weight: 700; letter-spacing: .01em; text-shadow: 0 2px 0 #0001; }
.logo-text b { color: var(--ink); margin-left: 2px; }

.actions { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.act-sep { width: 3px; height: 50px; background: #e6ecf5; border-radius: 3px; margin: 0 4px; }
.act {
  display: flex; flex-direction: column; align-items: center; gap: 5px;
  min-width: var(--tap);
  color: var(--d);
  transition: transform .12s;
}
.act-ic {
  width: 56px; height: 56px; padding: 11px;
  display: grid; place-items: center;
  border-radius: 50%;
  color: #fff;
  background: radial-gradient(circle at 35% 30%, #ffffff55, transparent 45%), var(--c);
  box-shadow: inset 0 -5px 0 #0002, 0 5px 0 var(--d);
  transition: transform .08s, box-shadow .08s;
}
.act:hover .act-ic { transform: translateY(-2px); }
.act:active .act-ic, .act.pressing .act-ic { transform: translateY(4px); box-shadow: inset 0 -2px 0 #0002, 0 1px 0 var(--d); }
.act:disabled { opacity: .35; cursor: default; }
.act:disabled .act-ic { transform: none; }
.act-sound .ic-off { display: none; }
.act-sound[aria-pressed="false"] .ic-on { display: none; }
.act-sound[aria-pressed="false"] .ic-off { display: block; }
.act-sound[aria-pressed="false"] { --c: #b8c0cc; --d: #8f98a6; }
.act-read.reading .act-ic { animation: pulse 1s ease-in-out infinite; }

/* ---------- Tool case ---------- */
.toolcase {
  position: relative;
  z-index: 2;
  background: var(--panel);
  border-radius: 30px;
  padding: 14px 16px 16px;
  box-shadow: 0 6px 0 #9fcbe866, 0 14px 30px #3a6c9a22;
}
.toolrow { display: flex; align-items: center; justify-content: center; gap: 22px; }
.divider { width: 3px; align-self: stretch; background: #eef1f7; border-radius: 3px; }

/* B I U look like real keyboard keys */
.keys { display: flex; gap: 12px; }
.key {
  width: var(--tap); height: var(--tap);
  border-radius: 18px;
  font-family: "Andika", serif;
  font-size: 42px;
  color: var(--key-d);
  background: linear-gradient(#fff, #eef6ff);
  border: 3px solid #cfe5f8;
  box-shadow: 0 6px 0 #b6d4ee;
  transition: transform .08s, box-shadow .08s, background .15s;
}
.key:hover { transform: translateY(-2px); box-shadow: 0 8px 0 #b6d4ee; }
.key:active, .key.pressing { transform: translateY(5px); box-shadow: 0 1px 0 #b6d4ee; }
.key[aria-pressed="true"] {
  color: #fff;
  background: linear-gradient(#55b4f5, var(--key));
  border-color: var(--key-d);
  box-shadow: 0 2px 0 var(--key-d), inset 0 3px 6px #0003;
  transform: translateY(4px);
}

/* Category buttons: Écriture / Taille / Couleur / Effets */
.cats { display: flex; gap: 12px; }
.cat {
  position: relative;
  width: 104px; height: 86px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
  border-radius: 22px;
  color: var(--d);
  background: var(--l);
  border: 3px solid transparent;
  transition: transform .12s, background .15s, color .15s;
}
.cat:hover { transform: translateY(-2px); }
.cat-ic {
  height: 40px; min-width: 40px;
  display: flex; align-items: flex-end; justify-content: center;
  font-size: 36px; font-weight: 700; line-height: 1;
}
.cat-ic small { font-size: 20px; margin-right: 2px; }
.cat-ic svg { width: 40px; height: 40px; }
.cat-ic svg .stroke { stroke-width: 6; }
.cat-color { position: relative; }
.colorbar { position: absolute; left: -7px; right: -7px; bottom: -7px; height: 9px; border-radius: 5px; background: #2b2550; box-shadow: 0 0 0 2px #fff; }
.cat[aria-selected="true"] {
  color: #fff;
  background: radial-gradient(circle at 30% 20%, #ffffff40, transparent 50%), var(--c);
  border-color: var(--d);
  box-shadow: 0 6px 0 var(--d);
  transform: translateY(-3px);
}
/* little arrow pointing down at the tray */
.cat[aria-selected="true"]::after {
  content: "";
  position: absolute;
  bottom: -16px; left: 50%;
  width: 18px; height: 18px;
  background: var(--c);
  border-right: 3px solid var(--d);
  border-bottom: 3px solid var(--d);
  transform: translateX(-50%) rotate(45deg);
  border-radius: 0 0 4px 0;
}

/* ---------- Tray: options of the open category ---------- */
.tray {
  margin-top: 16px;
  display: flex; justify-content: center; align-items: center; flex-wrap: wrap;
  gap: 14px;
  padding: 14px;
  min-height: 118px;
  border-radius: 22px;
  background: var(--tray-l, #f4f6fa);
  border: 3px dashed var(--tray-c, #dde3ec);
  transition: background .2s, border-color .2s;
}
.tile {
  position: relative;
  width: 106px; height: 90px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  border-radius: 20px;
  background: #fff;
  border: 3px solid #fff;
  box-shadow: 0 5px 0 #0000001a;
  transition: transform .1s, box-shadow .1s, border-color .1s;
}
.tile:hover { transform: translateY(-3px); box-shadow: 0 8px 0 #0000001a; }
.tile:active, .tile.pressing { transform: translateY(3px) scale(.97); box-shadow: 0 1px 0 #0000001a; }
.tile .cap { color: var(--ink-soft); font-size: 14px; }
.tile .sample { font-size: 38px; line-height: 1.05; height: 52px; display: flex; align-items: center; color: var(--ink); }
.tile[aria-pressed="true"] { border-color: var(--tray-c); box-shadow: 0 5px 0 var(--tray-d); }
.tile[aria-pressed="true"] .cap { color: var(--tray-d); }
/* green check badge on the chosen option */
.tile[aria-pressed="true"]::after {
  content: "";
  position: absolute; top: -10px; right: -10px;
  width: 30px; height: 30px;
  border-radius: 50%;
  background: #2ec27e url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M5 12.5l4.5 4.5L19 7.5' fill='none' stroke='white' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E") center/20px no-repeat;
  box-shadow: 0 0 0 3px #fff, 0 3px 0 3px #0001;
  animation: pop .25s ease-out;
}

.tile-size .sample { align-items: flex-end; }
.tile-color { width: 88px; }
.tile-color .drop {
  width: 52px; height: 52px; border-radius: 50%;
  background: radial-gradient(circle at 32% 28%, #ffffff88, transparent 38%), var(--dot);
  box-shadow: inset 0 -6px 0 #0002;
}
/* Effect previews use the colour and writing the child currently has */
.tile-fx .sample {
  color: var(--cur-color, var(--ink));
  --glow: var(--cur-glow, #29b6ff);
  font-family: var(--cur-font, "Andika");
  text-transform: var(--cur-case, uppercase);
  font-size: 34px;
  font-weight: 700;
}
.tile-fx[data-value="none"] { border: 3px dashed #c9cfda; box-shadow: none; background: #ffffffaa; }
.tile-fx[data-value="none"] .sample { font-weight: 400; }
.tile-fx[data-value="none"][aria-pressed="true"] { border-style: solid; border-color: var(--tray-c); }
.tile-fx[data-value="neon"] { background: #24204a; border-color: #24204a; }
.tile-fx[data-value="neon"] .cap { color: #d8d4ff; }
.tile-fx[data-value="neon"][aria-pressed="true"] { border-color: var(--tray-c); }

.tray[data-tab="font"] { --tray-c: #9b6cf0; --tray-d: #7346cc; --tray-l: #f3ecff; }
.tray[data-tab="size"] { --tray-c: #2ec27e; --tray-d: #1e9a62; --tray-l: #e6f9ef; }
.tray[data-tab="color"] { --tray-c: #ff5d8f; --tray-d: #d93b6e; --tray-l: #ffecf2; }
.tray[data-tab="fx"] { --tray-c: #ffa41b; --tray-d: #dd7f00; --tray-l: #fff4e0; }

/* ---------- Notebook ---------- */
.desk { position: relative; z-index: 1; flex: 1; overflow: auto; padding: 18px 4px 110px; }
.notebook { position: relative; max-width: 1000px; margin: 0 auto; }
.rings {
  position: absolute; top: -14px; left: 40px; right: 40px; height: 34px; z-index: 2;
  background:
    radial-gradient(circle at 50% 70%, #d7dde8 0 7px, transparent 8px) 0 0 / 46px 34px repeat-x;
}
.rings::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent 17px, #8e98ab 17px 29px, transparent 29px) 0 0 / 46px 22px repeat-x;
  border-radius: 6px;
  -webkit-mask: linear-gradient(#000, #000) 0 0 / 100% 22px no-repeat;
  mask: linear-gradient(#000, #000) 0 0 / 100% 22px no-repeat;
}
.sheet {
  position: relative;
  min-height: 100%;
  background-color: var(--paper);
  border-radius: 18px;
  box-shadow: 0 6px 0 #d9e6f2, 0 18px 40px #3a6c9a26;
  padding: 44px 56px 40px 96px;
  /* French school notebook: a red margin and soft writing lines */
  background-image:
    linear-gradient(90deg, transparent 72px, #ff8fab 72px 74px, transparent 74px),
    linear-gradient(transparent calc(100% - 2px), #c9dcf5 0),
    linear-gradient(transparent calc(100% - 1px), #edf2fa 0);
  background-size: 100% 100%, 100% 64px, 100% 16px;
  background-position: 0 0, 0 32px, 0 32px;
}
.editor {
  min-height: 360px;
  outline: none;
  font-family: "Andika", sans-serif;
  font-size: 40px;
  line-height: 64px;
  color: #1f1b3d;
  caret-color: #ff5d8f;
  /* Default writing is lowercase "script"; the Bâton option turns capitals on */
  text-transform: none;
  user-select: text;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.editor:empty::before {
  content: "";
  display: inline-block;
  width: 46px; height: 46px;
  vertical-align: middle;
  opacity: .35;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 64 64'%3E%3Cpath d='M44 8l12 12-30 30-16 4 4-16z' fill='%23ffb020'/%3E%3Cpath d='M44 8l12 12-5 5-12-12z' fill='%23ff5d8f'/%3E%3Cpath d='M14 38l12 12-16 4z' fill='%23e8c48a'/%3E%3C/svg%3E") center/contain no-repeat;
  animation: wiggle 1.6s ease-in-out infinite;
}

/* The word a tool will change: yellow marker. What just changed: brief flash. */
::highlight(pe-target) { background-color: #ffdd3352; }
::highlight(pe-flash) { background-color: #ffd23f; }

/* Formatting written by format.js. Spans carry data-* so the look lives here. */
.editor [data-font="baton"] { font-family: "Andika", sans-serif; text-transform: uppercase; }
.editor [data-font="script"] { font-family: "Andika", sans-serif; text-transform: none; }
.editor [data-font="cursive"] { font-family: "Playwrite FR Moderne", cursive; text-transform: none; }
.editor [data-font="bubble"] { font-family: "Fredoka", sans-serif; text-transform: none; }
.editor [data-font="comic"] { font-family: "Luckiest Guy", sans-serif; text-transform: none; letter-spacing: .03em; }

.editor [data-size="s"] { font-size: 26px; }
.editor [data-size="m"] { font-size: 40px; }
.editor [data-size="l"] { font-size: 60px; }
.editor [data-size="xl"] { font-size: 88px; line-height: 1.1; }

/* Effects: one at a time. They use the text colour; neon glows in it (blue when the text is black). */
.fx-shadow, .editor [data-fx="shadow"] { text-shadow: .07em .07em 0 #0000004d; }
.fx-outline, .editor [data-fx="outline"] { -webkit-text-stroke: .075em currentColor; -webkit-text-fill-color: #fff; paint-order: stroke fill; }
.fx-neon, .editor [data-fx="neon"] { text-shadow: 0 0 .05em #fff, 0 0 .2em var(--glow, #29b6ff), 0 0 .45em var(--glow, #29b6ff), 0 0 .8em var(--glow, #29b6ff); }
.fx-rainbow, .editor [data-fx="rainbow"] {
  background: linear-gradient(90deg, #ff4d5e, #ff9f1c, #ffd60a, #2ec27e, #3aa0e8, #9b6cf0);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.fx-3d, .editor [data-fx="3d"] { text-shadow: .02em .02em 0 #0005, .04em .04em 0 #0005, .06em .06em 0 #0004, .08em .08em 0 #0004, .12em .12em .08em #0003; }
.fx-none, .editor [data-fx="none"] { text-shadow: none; -webkit-text-stroke: 0; -webkit-text-fill-color: currentColor; background: none; }

/* ---------- Hint pill (replaces any character: just a voice + text) ---------- */
.hint {
  position: fixed; left: 50%; bottom: 18px; z-index: 5;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 12px;
  max-width: min(640px, calc(100vw - 32px));
  padding: 10px 22px 10px 10px;
  background: #2b2550;
  color: #fff;
  border-radius: 999px;
  box-shadow: 0 6px 0 #17132f, 0 14px 30px #2b255044;
  font-size: 22px; font-weight: 600;
  text-align: left;
}
.hint-ic {
  flex: none; width: 46px; height: 46px; padding: 9px;
  border-radius: 50%;
  background: #ffd23f; color: #2b2550;
}
.hint.pop { animation: hintpop .35s ease-out; }
.hint.talk .hint-ic { animation: pulse .6s ease-in-out 2; }

/* ---------- New page confirm ---------- */
.confirm { position: fixed; inset: 0; z-index: 10; display: grid; place-items: center; background: #2b255088; backdrop-filter: blur(3px); }
.confirm[hidden] { display: none; }
.confirm-box { background: #fff; border-radius: 32px; padding: 28px 44px 34px; text-align: center; box-shadow: 0 10px 0 #0002; animation: pop .25s ease-out; }
.confirm-ic { width: 96px; height: 96px; margin: 0 auto; padding: 16px; border-radius: 50%; background: #ffecf2; color: #d93b6e; }
.confirm-box p { font-size: 32px; font-weight: 700; margin: 12px 0 22px; }
.confirm-btns { display: flex; gap: 40px; justify-content: center; }
.confirm-btns button { width: 124px; height: 124px; border-radius: 32px; color: #fff; padding: 22px; transition: transform .08s, box-shadow .08s; }
.confirm-btns button:active { transform: translateY(6px); }
.confirm-btns .yes { background: #2ec27e; box-shadow: 0 7px 0 #1e9a62; }
.confirm-btns .no { background: #ff5d8f; box-shadow: 0 7px 0 #d93b6e; }
.confirm-btns .yes:active { box-shadow: 0 1px 0 #1e9a62; }
.confirm-btns .no:active { box-shadow: 0 1px 0 #d93b6e; }
.confirm-btns svg .stroke { stroke-width: 7; }

/* ---------- Motion ---------- */
.bounce { animation: bounce .35s ease-out; }
@keyframes bounce { 0% { scale: 1; } 40% { scale: 1.12; } 100% { scale: 1; } }
@keyframes pop { 0% { transform: scale(.7); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }
@keyframes hintpop { 0% { transform: translateX(-50%) scale(.85); } 60% { transform: translateX(-50%) scale(1.04); } 100% { transform: translateX(-50%) scale(1); } }
@keyframes pulse { 0%, 100% { transform: scale(1); } 50% { transform: scale(1.15); } }
@keyframes wiggle { 0%, 100% { transform: rotate(-8deg); } 50% { transform: rotate(8deg); } }
@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------- Smaller school screens (1366×768) and tablets ---------- */
@media (max-width: 1200px) {
  .logo-text { font-size: 28px; }
  .toolrow { gap: 14px; }
  .cats, .keys { gap: 10px; }
}
@media (max-width: 1100px) {
  :root { --tap: 64px; }
  .logo-text { display: none; }
  .act { min-width: 60px; }
  .act-ic { width: 50px; height: 50px; padding: 10px; }
  .actions { gap: 6px; }
  .cap { font-size: 13px; }
  .cat { width: 90px; height: 80px; }
  .tile { width: 92px; height: 82px; }
  .sheet { padding: 36px 32px 32px 76px; background-image:
    linear-gradient(90deg, transparent 56px, #ff8fab 56px 58px, transparent 58px),
    linear-gradient(transparent calc(100% - 2px), #c9dcf5 0),
    linear-gradient(transparent calc(100% - 1px), #edf2fa 0); }
}
@media (max-width: 820px) {
  .toolrow { flex-wrap: wrap; }
  .divider { display: none; }
}
@media (max-height: 800px) {
  body { gap: 10px; padding-top: 10px; }
  .act-ic { width: 50px; height: 50px; padding: 10px; }
  .logo-mark { width: 50px; height: 50px; padding: 8px; }
  .toolcase { padding: 10px 14px 12px; }
  .cat { height: 78px; }
  .tray { margin-top: 14px; min-height: 0; padding: 10px; }
  .tile { height: 80px; }
  .tile .sample { height: 44px; }
  .hint { font-size: 19px; padding: 8px 18px 8px 8px; }
  .hint-ic { width: 40px; height: 40px; padding: 8px; }
}

/* ---------- Print: only the sheet ---------- */
@media print {
  body { background: #fff; overflow: visible; display: block; padding: 0; }
  .sky, .topbar, .toolcase, .hint, .confirm, .rings { display: none !important; }
  .desk { padding: 0; overflow: visible; }
  .sheet { box-shadow: none; background-image: none; padding: 0; }
  .editor { min-height: 0; }
}
