/* Cypherworld — Metro (Windows 8.1 / Lumia) shell.
   No inline styles anywhere (CSP style-src 'self'); runtime values arrive as custom
   properties set through CSSOM: --accent on :root, --x/--y/--w/--h on tile slots. */

/* ---------- fonts: Open Sans (OFL, see /fonts/OFL.txt) stands in for Segoe UI ---------- */
@font-face {
  font-family: "Open Sans"; font-style: normal; font-weight: 300; font-display: swap;
  src: url(/fonts/open-sans-latin-300-normal.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: "Open Sans"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(/fonts/open-sans-latin-400-normal.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: "Open Sans"; font-style: normal; font-weight: 600; font-display: swap;
  src: url(/fonts/open-sans-latin-600-normal.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: "Open Sans"; font-style: normal; font-weight: 300; font-display: swap;
  src: url(/fonts/open-sans-latin-ext-300-normal.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-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Open Sans"; font-style: normal; font-weight: 400; font-display: swap;
  src: url(/fonts/open-sans-latin-ext-400-normal.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-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Open Sans"; font-style: normal; font-weight: 600; font-display: swap;
  src: url(/fonts/open-sans-latin-ext-600-normal.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-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- tokens ---------- */
:root {
  --accent: #1BA1E2;
  --bg: #1D1D1D;
  --fg: #FFFFFF;
  --fg-2: rgba(255, 255, 255, 0.62);
  --chrome: #2A2A2A;
  --hover: rgba(255, 255, 255, 0.1);
  --badge-bg: #FFFFFF;
  --badge-fg: #1D1D1D;
  --font: "Segoe UI", "Open Sans", system-ui, "Noto Sans Malayalam", sans-serif;
  --margin: 120px;
  --head-top: 44px;
  --ease-out: cubic-bezier(0.1, 0.9, 0.2, 1);
  --ease-in: cubic-bezier(0.7, 0, 1, 0.5);
  color-scheme: dark;
}
:root[data-theme="light"] {
  --bg: #FFFFFF;
  --fg: #1D1D1D;
  --fg-2: rgba(0, 0, 0, 0.6);
  --chrome: #EBEBEB;
  --hover: rgba(0, 0, 0, 0.07);
  --badge-bg: #1D1D1D;
  --badge-fg: #FFFFFF;
  color-scheme: light;
}
@media (max-width: 1024px) { :root { --margin: 48px; } }
@media (max-width: 600px)  { :root { --margin: 16px; --head-top: calc(24px + env(safe-area-inset-top)); } }

/* ---------- base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html {
  background: var(--bg);
  color: var(--fg);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.4;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}
html.is-transitioning { overflow: hidden; }
body { margin: 0; min-height: 100vh; min-height: 100dvh; background: var(--bg); }
button { font: inherit; color: inherit; }
h1, h2, h3, p { margin: 0; }
.visually-hidden {
  position: absolute !important; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap;
}
.view { min-height: 100vh; min-height: 100dvh; }
:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; }

.icon {
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linejoin: miter;
  stroke-linecap: butt;
  overflow: visible;
}

/* ---------- Start ---------- */
.start {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  user-select: none;
  -webkit-user-select: none;
}
.start-header {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--head-top) calc(var(--margin) - 8px) 0 var(--margin);
}
.start-title {
  font-size: 42px;
  font-weight: 300;
  line-height: 52px;
  letter-spacing: -0.01em;
}
.icon-button {
  appearance: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: var(--fg);
  opacity: 0.75;
  cursor: pointer;
  transition: opacity 120ms, background-color 120ms;
}
.icon-button .icon { width: 22px; height: 22px; stroke-width: 3.4; }
.icon-button:hover { opacity: 1; background: var(--hover); }
.icon-button:active { opacity: 0.6; }

.start-scroll {
  flex: 1;
  min-height: 0;
  display: flex;
  align-items: flex-start;
  padding: 44px 0 56px var(--margin);
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: thin;
  scrollbar-color: rgba(128, 128, 128, 0.45) transparent;
  overscroll-behavior-x: contain;
}
.start-scroll::after { content: ""; flex: none; width: var(--margin); height: 1px; }
.start-empty {
  display: none;
  max-width: 440px;
  font-size: 20px;
  font-weight: 300;
  line-height: 1.35;
  color: var(--fg-2);
}
.start.is-empty .start-empty { display: block; }

.tiles {
  position: relative;
  flex: none;
  width: var(--tiles-w, 0px);
  height: var(--tiles-h, 0px);
  perspective: 1600px;
  perspective-origin: 0 50%;
}
.slot {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--w);
  height: var(--h);
  transform: translate3d(var(--x), var(--y), 0);
  transform-origin: 0 50%;
}
.tiles.is-animated .slot {
  transition: transform 320ms var(--ease-out), width 320ms var(--ease-out), height 320ms var(--ease-out);
}
.tiles .slot.is-dragging { transition: none; z-index: 10; }

/* the tile itself (a button) */
.tile {
  appearance: none;
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: transparent;
  color: #FFFFFF;
  text-align: left;
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  user-select: none;
  -webkit-user-select: none;
  transition: inset 220ms var(--ease-out), opacity 220ms;
}
.tile:focus-visible { outline: 2px solid var(--fg); outline-offset: 2px; z-index: 1; }
.tile-body {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: var(--accent);
  transform: perspective(800px) rotateX(0deg) rotateY(0deg) scale(1);
  transition: transform 240ms var(--ease-out);
}
.tile-body::after {
  content: "";
  position: absolute;
  inset: 0;
  border: 2px solid transparent;
  pointer-events: none;
  transition: border-color 120ms;
}
@media (hover: hover) and (pointer: fine) {
  .tile:hover .tile-body::after { border-color: rgba(255, 255, 255, 0.28); }
}
.tile.is-pressed .tile-body {
  transform: perspective(800px) rotateX(var(--rx, 0deg)) rotateY(var(--ry, 0deg)) scale(var(--s, 0.97));
  transition-duration: 90ms;
}

.tile-face {
  position: absolute;
  inset: 0;
  display: flex;
  visibility: hidden;
  backface-visibility: hidden;
  -webkit-backface-visibility: hidden;
  transform-origin: 50% 50%;
}
.tile-face.is-current { visibility: visible; }
.tile-face.is-current.is-entering { visibility: hidden; }
.tile-face--icon { align-items: center; justify-content: center; }
.tile-icon { width: 56px; height: 56px; }
.tile--small .tile-icon { width: 34px; height: 34px; stroke-width: 2.7; }
.tile--wide .tile-icon { width: 60px; height: 60px; }

.tile-label {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 6px;
  font-size: 13px;
  font-weight: 400; /* closest to Segoe UI Semilight */
  line-height: 16px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  pointer-events: none;
}
.tile--small .tile-label { display: none; }

/* live text faces */
.tile-face--text {
  flex-direction: column;
  align-items: stretch;
  gap: 4px;
  padding: 10px 12px 30px;
  overflow: hidden;
  overflow-wrap: anywhere;
}
.face-head, .face-body {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.face-head {
  font-size: 20px;
  font-weight: 400;
  line-height: 24px;
  -webkit-line-clamp: 2;
  line-clamp: 2;
}
.face-body {
  font-size: 14px;
  font-weight: 400;
  line-height: 18px;
  opacity: 0.92;
  -webkit-line-clamp: 3;
  line-clamp: 3;
}
.tile--wide .face-head { -webkit-line-clamp: 1; line-clamp: 1; }
.tile--wide .face-body { -webkit-line-clamp: 4; line-clamp: 4; }
.tile--small .tile-face--text {
  justify-content: center;
  align-items: center;
  text-align: center;
  gap: 1px;
  padding: 6px;
}
.tile--small .face-head { font-size: 14px; font-weight: 600; line-height: 18px; -webkit-line-clamp: 1; line-clamp: 1; }
.tile--small .face-body { font-size: 11px; line-height: 14px; -webkit-line-clamp: 1; line-clamp: 1; }

/* ---------- customise mode ---------- */
.start.is-customising .tile { inset: 6px; width: auto; height: auto; }
.start.is-customising .tile-body { transform: none; }
.start.is-customising .slot.is-dragging .tile { inset: -4px; opacity: 0.92; }
.start.is-customising .tile { touch-action: none; cursor: grab; }
.start.is-customising .slot.is-dragging .tile { cursor: grabbing; }
.badge {
  appearance: none;
  position: absolute;
  right: -4px;
  z-index: 2;
  display: none;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--badge-bg);
  color: var(--badge-fg);
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.badge::before { content: ""; position: absolute; inset: -8px; } /* larger touch target */
.badge-unpin { top: -4px; }
.badge-size { bottom: -4px; }
.badge-glyph { width: 16px; height: 16px; stroke-width: 4.5; }
.badge:active { transform: scale(0.9); }
.start.is-customising .badge { display: grid; animation: badge-in 200ms var(--ease-out); }
.start.is-customising .slot.is-dragging .badge,
.start.is-customising .slot.is-leaving .badge { display: none; }
@keyframes badge-in { from { transform: scale(0.4); opacity: 0; } to { transform: none; opacity: 1; } }

/* app bar (customise) */
.appbar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 24px;
  min-height: 92px;
  padding: 12px calc(var(--margin) - 8px) calc(12px + env(safe-area-inset-bottom)) var(--margin);
  background: var(--chrome);
  transform: translateY(100%);
  visibility: hidden;
  transition: transform 260ms var(--ease-in), visibility 0s 260ms;
}
.start.is-customising .appbar {
  transform: none;
  visibility: visible;
  transition: transform 300ms var(--ease-out), visibility 0s;
}
.appbar-add {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 16px;
  overflow-x: auto;
  scrollbar-width: none;
}
.appbar-add-label { flex: none; font-size: 15px; font-weight: 600; }
.add-tile {
  appearance: none;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 2px;
  border: 0;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  font-size: 12px;
  line-height: 16px;
}
.add-tile-swatch {
  display: grid;
  place-items: center;
  width: 48px;
  height: 48px;
  background: var(--accent);
  color: #FFFFFF;
  transition: transform 120ms var(--ease-out);
}
.add-tile-swatch .icon { width: 28px; height: 28px; stroke-width: 2.6; }
.add-tile:active .add-tile-swatch { transform: scale(0.94); }
.appbar-msg { flex: none; max-width: 280px; font-size: 13px; color: var(--fg-2); }
.appbar-msg:empty { display: none; }
.appbar-command {
  appearance: none;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 68px;
  padding: 2px 4px;
  border: 0;
  background: transparent;
  color: var(--fg);
  font-size: 12px;
  line-height: 16px;
  cursor: pointer;
}
.appbar-glyph {
  box-sizing: content-box;
  width: 20px;
  height: 20px;
  padding: 8px;
  border: 2px solid currentColor;
  border-radius: 50%;
  stroke-width: 4;
  transition: background-color 120ms, color 120ms;
}
.appbar-command:hover .appbar-glyph { background: var(--hover); }
.appbar-command:active .appbar-glyph { background: var(--fg); color: var(--chrome); }
.appbar-command:disabled { opacity: 0.5; cursor: default; }

/* ---------- hubs (placeholder; Task 11 adds the panorama) ---------- */
.hub {
  min-height: 100vh;
  min-height: 100dvh;
  padding: var(--head-top) var(--margin) 48px;
  transform-origin: 0 50%;
  touch-action: pan-y; /* horizontal touch drags reach JS: swipe-right goes back */
}
.hub-head { position: relative; display: flex; align-items: center; gap: 20px; min-height: 52px; }
.hub-title {
  min-width: 0;
  font-size: 56px;
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -0.01em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hub-soon { margin-top: 36px; font-size: 20px; font-weight: 300; color: var(--fg-2); }
.back-button {
  appearance: none;
  flex: none;
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 0;
  border: 2px solid var(--fg);
  border-radius: 50%;
  background: transparent;
  color: var(--fg);
  cursor: pointer;
  transition: background-color 120ms, color 120ms;
}
.back-button .icon { width: 22px; height: 22px; stroke-width: 4; }
.back-button:hover { background: var(--hover); }
.back-button:active { background: var(--fg); color: var(--bg); }
@media (min-width: 601px) {
  .hub-head .back-button { position: absolute; left: -72px; top: 50%; margin-top: -20px; }
}

.boot-error { padding: var(--head-top) var(--margin); font-size: 20px; font-weight: 300; color: var(--fg-2); }

/* ---------- phone (Lumia): one endless 2-column block ---------- */
@media (max-width: 600px) {
  .start { height: auto; min-height: 100dvh; }
  .start-header { padding-right: 8px; }
  .start-scroll {
    display: block;
    padding: 20px var(--margin) calc(40px + env(safe-area-inset-bottom));
    overflow: visible;
  }
  .start-scroll::after { content: none; }
  .start.is-customising .start-scroll { padding-bottom: 160px; }
  .appbar { gap: 12px; min-height: 84px; }
  .appbar-add { gap: 12px; }
  .appbar-add-label { display: none; }
  .hub-title { font-size: 42px; }
}

/* ---------- sign-in ---------- */
.login-page, .login-page body { background: var(--accent); color: #FFFFFF; }
.login {
  display: grid;
  place-items: center;
  min-height: 100vh;
  min-height: 100dvh;
  padding: 32px 16px calc(32px + env(safe-area-inset-bottom));
}
.login-form { position: relative; width: min(400px, 100%); }
.login-title {
  font-size: 56px;
  font-weight: 300;
  line-height: 1.1;
  letter-spacing: -0.015em;
  margin-left: -3px; /* optical alignment of the light "C" */
}
.login-sub { margin: 6px 0 28px; font-size: 17px; font-weight: 300; opacity: 0.9; }
.metro-input {
  display: block;
  width: 100%;
  height: 40px;
  padding: 0 10px;
  border: 2px solid #FFFFFF;
  border-radius: 0;
  background: #FFFFFF;
  color: #1D1D1D;
  font: inherit;
  font-size: 16px; /* no zoom-on-focus on iOS */
  outline: none;
  appearance: none;
  transition: box-shadow 120ms;
}
.metro-input::placeholder { color: #767676; }
.metro-input:focus { box-shadow: 0 0 0 2px rgba(0, 0, 0, 0.35); }
.login-form.has-error .metro-input { box-shadow: 0 0 0 2px #FFFFFF, 0 0 0 4px rgba(0, 0, 0, 0.35); }
.login-error {
  min-height: 22px;
  margin: 10px 0 14px;
  font-size: 14px;
  font-weight: 600;
  line-height: 22px;
}
.metro-button {
  appearance: none;
  min-width: 120px;
  height: 40px;
  padding: 0 20px;
  border: 2px solid #FFFFFF;
  border-radius: 0;
  background: transparent;
  color: #FFFFFF;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 120ms, color 120ms;
}
.metro-button:hover { background: rgba(255, 255, 255, 0.14); }
.metro-button:active { background: #FFFFFF; color: var(--accent); }
.metro-button:disabled { opacity: 0.6; cursor: default; }
.login .metro-button:focus-visible, .login .metro-input:focus-visible { outline: 2px solid #FFFFFF; outline-offset: 3px; }
@media (max-width: 600px) {
  .login { place-items: start stretch; padding-top: calc(18vh + env(safe-area-inset-top)); }
  .login-title { font-size: 46px; }
}

/* Metro progress dots while signing in */
.progress-dots { position: absolute; left: 0; right: 0; top: -36px; height: 4px; overflow: hidden; visibility: hidden; }
.is-busy .progress-dots { visibility: visible; }
.progress-dots span {
  position: absolute;
  top: 0;
  left: 0;
  width: 4px;
  height: 4px;
  background: #FFFFFF;
  border-radius: 50%;
  opacity: 0;
}
.is-busy .progress-dots span { animation: dot 2.4s infinite var(--ease-out); }
.is-busy .progress-dots span:nth-child(2) { animation-delay: 0.12s; }
.is-busy .progress-dots span:nth-child(3) { animation-delay: 0.24s; }
.is-busy .progress-dots span:nth-child(4) { animation-delay: 0.36s; }
.is-busy .progress-dots span:nth-child(5) { animation-delay: 0.48s; }
@keyframes dot {
  0% { transform: translateX(0); opacity: 0; }
  10% { opacity: 1; }
  35% { transform: translateX(calc(min(400px, 100vw - 32px) * 0.45)); }
  65% { transform: translateX(calc(min(400px, 100vw - 32px) * 0.55)); opacity: 1; }
  80%, 100% { transform: translateX(min(400px, 100vw - 32px)); opacity: 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
