/* ==========================================================================
   Kansalaisuuskoe - design tokens
   Source: Kansalaisuuskoe_UI-tyylijarjestelma.pdf (Maahanmuuttovirasto)
   ========================================================================== */

:root {
  /* Primary colors */
  --color-blue-600: #003da5; /* actions, links, headings, header */
  --color-blue-200: #a6d1f2; /* highlighted surfaces, selected state */

  /* Blue-600 tints (surfaces only, never text) */
  --color-blue-600-80: #3364b7;
  --color-blue-600-60: #6688c9;
  --color-blue-600-40: #99b1db;
  --color-blue-600-20: #ccd8ed;
  --color-blue-600-10: #e6ecf6;

  /* Blue-200 tints */
  --color-blue-200-80: #b8daf5;
  --color-blue-200-60: #cae2f7;
  --color-blue-200-40: #dbecf9;
  --color-blue-200-20: #edf6fc;
  --color-blue-200-10: #f6fafe;

  /* Semantic colors */
  --color-green-600: #00664a; /* success */
  --color-green-600-20: #cce0db;
  --color-green-600-10: #e6f2ee;
  --color-red-600: #d12e15; /* error */
  --color-yellow-300: #f7e88c; /* tip / focus on dark */
  --color-purple-600: #5f58b0; /* illustration, category, visited link */
  --color-orange-400: #ff8c59; /* illustration, category */

  /* Neutrals */
  --color-text: #1b1b1b;
  --color-text-muted: #4b5563;
  --color-bg: #f4f7fb;
  --color-surface: #ffffff;
  --color-border-input: #5b6b86;
  --color-border: #ccd8ed;

  /* Fonts */
  --font-base: "Noto Sans", Arial, Helvetica, sans-serif;

  /* Type scale: desktop */
  --text-display-size: 48px;
  --text-display-line: 56px;
  --text-h1-size: 40px;
  --text-h1-line: 48px;
  --text-h2-size: 32px;
  --text-h2-line: 40px;
  --text-h3-size: 24px;
  --text-h3-line: 32px;
  --text-h4-size: 20px;
  --text-h4-line: 28px;
  --text-lead-size: 20px;
  --text-lead-line: 32px;
  --text-body-size: 18px;
  --text-body-line: 29px;
  --text-base-size: 16px;
  --text-base-line: 26px;
  --text-small-size: 14px;
  --text-small-line: 22px;
  --text-caption-size: 13px;
  --text-caption-line: 20px;

  /* Spacing (4px base unit) */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --space-16: 64px;

  /* Shape */
  --radius: 12px;
  --radius-small: 8px;

  /* Layout */
  --content-max-width: 1200px;
  --measure-max-width: 70ch;
  --focus-ring: 0 0 0 3px #ffffff, 0 0 0 5px var(--color-blue-600);
}

@media (max-width: 639px) {
  :root {
    --text-display-size: 34px;
    --text-display-line: 42px;
    --text-h1-size: 30px;
    --text-h1-line: 38px;
    --text-h2-size: 26px;
    --text-h2-line: 34px;
    --text-h3-size: 22px;
    --text-h3-line: 30px;
  }
}

/* ==========================================================================
   Reset & base
   ========================================================================== */

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

html {
  -webkit-text-size-adjust: 100%;
  height: 100%;
}

body {
  margin: 0;
  min-height: 100%;
  display: flex;
  flex-direction: column;
  font-family: var(--font-base);
  font-size: var(--text-body-size);
  line-height: var(--text-body-line);
  color: var(--color-text);
  background: var(--color-bg);
  font-display: swap;
}

h1,
h2,
h3,
h4,
p,
ul,
ol,
figure,
table {
  margin: 0 0 var(--space-4) 0;
}

h1,
h2,
h3,
h4 {
  color: var(--color-blue-600);
  font-weight: 700;
}

h1 {
  font-size: var(--text-h1-size);
  line-height: var(--text-h1-line);
}

h2 {
  font-size: var(--text-h2-size);
  line-height: var(--text-h2-line);
}

h3 {
  font-size: var(--text-h3-size);
  line-height: var(--text-h3-line);
  font-weight: 600;
}

h4 {
  font-size: var(--text-h4-size);
  line-height: var(--text-h4-line);
  font-weight: 600;
}

p {
  max-width: var(--measure-max-width);
}

a {
  color: var(--color-blue-600);
}

a:visited {
  color: var(--color-purple-600);
}

a:focus-visible,
button:focus-visible,
summary:focus-visible,
input:focus-visible,
select:focus-visible {
  outline: 3px solid var(--color-blue-600);
  outline-offset: 2px;
  border-radius: var(--radius-small);
}

strong {
  font-weight: 700;
}

/* ==========================================================================
   Skip link
   ========================================================================== */

.kk-skip-link {
  position: absolute;
  top: -48px;
  left: var(--space-4);
  z-index: 100;
  background: #ffffff;
  color: var(--color-blue-600);
  font-weight: 600;
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-small);
  border: 2px solid var(--color-blue-600);
  text-decoration: none;
  transition: top 0.15s ease;
}

.kk-skip-link:focus {
  top: var(--space-4);
}

main:focus-visible {
  outline: 3px solid var(--color-blue-600);
  outline-offset: 4px;
}

ul,
ol {
  padding-left: var(--space-6);
  max-width: var(--measure-max-width);
}

li + li {
  margin-top: var(--space-2);
}

/* ==========================================================================
   Header
   ========================================================================== */

.kk-header {
  background: var(--color-blue-600);
  color: #ffffff;
}

.kk-header-inner {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-4) var(--space-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: var(--space-4);
}

.kk-logo {
  color: #ffffff;
  text-decoration: none;
  font-weight: 700;
  font-size: var(--text-h4-size);
}

.kk-logo:visited {
  color: #ffffff;
}

.kk-top-nav {
  display: flex;
  gap: var(--space-6);
}

.kk-top-nav a {
  color: #ffffff;
  text-decoration: underline;
  font-weight: 400;
}

.kk-top-nav a:visited {
  color: #ffffff;
}

.kk-lang-switch {
  display: flex;
  gap: var(--space-4);
  margin-left: auto;
}

.kk-lang-switch a {
  color: #ffffff;
  text-decoration: underline;
  font-size: var(--text-small-size);
  font-weight: 600;
}

.kk-lang-switch a:visited {
  color: #ffffff;
}

.kk-header a:focus-visible,
.kk-footer a:focus-visible {
  outline: 3px solid #ffffff;
  outline-offset: 2px;
}

/* ==========================================================================
   Page intro: breadcrumb + title
   ========================================================================== */

.kk-page-intro {
  background: var(--color-blue-200-20);
  border-bottom: 1px solid var(--color-border);
}

.kk-page-intro > * {
  max-width: var(--content-max-width);
  margin-left: auto;
  margin-right: auto;
  padding-left: var(--space-4);
  padding-right: var(--space-4);
}

.kk-breadcrumb {
  font-size: var(--text-small-size);
  line-height: var(--text-small-line);
  color: var(--color-text-muted);
  padding-top: var(--space-4);
}

.kk-page-intro h1 {
  padding-bottom: var(--space-6);
}

/* ==========================================================================
   Layout: sidebar + content
   ========================================================================== */

.kk-layout {
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-6) var(--space-4);
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: var(--space-8);
  align-items: start;
}

.kk-layout > * {
  min-width: 0;
}

@media (max-width: 899px) {
  .kk-layout {
    grid-template-columns: 1fr;
  }
}

.kk-layout .kk-nav-toggle {
  display: none;
}

@media (max-width: 899px) {
  html.kk-js-nav .kk-layout .kk-nav-toggle {
    display: flex;
    width: 100%;
    margin-bottom: var(--space-4);
  }

  html.kk-js-nav .kk-sidebar {
    display: none;
  }

  html.kk-js-nav .kk-sidebar.is-open {
    display: block;
  }
}

/* ==========================================================================
   Sidebar navigation ("Luvut")
   ========================================================================== */

.kk-sidebar {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-4);
  position: sticky;
  top: var(--space-4);
  font-size: var(--text-base-size);
  line-height: var(--text-base-line);
}

@media (max-width: 899px) {
  .kk-sidebar {
    position: static;
  }
}

.kk-sidebar ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.kk-nav-topics > li + li {
  margin-top: var(--space-4);
}

.kk-sidebar details > summary {
  list-style: none;
}

.kk-sidebar details > summary::-webkit-details-marker {
  display: none;
}

.kk-nav-group-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-2);
  font-weight: 700;
  color: var(--color-blue-600);
  padding: var(--space-2) var(--space-1);
  cursor: pointer;
  border-radius: var(--radius-small);
  overflow-wrap: break-word;
}

.kk-nav-group-label:hover {
  background: var(--color-blue-200-20);
}

.kk-nav-group-label::after {
  content: "";
  flex-shrink: 0;
  width: 10px;
  height: 10px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(45deg);
  transition: transform 0.15s ease;
}

details[open] > .kk-nav-group-label::after {
  transform: rotate(-135deg);
}

.kk-nav-subtopic {
  margin-top: var(--space-2);
}

.kk-nav-subtopic .kk-nav-group-label {
  font-weight: 600;
  font-size: var(--text-small-size);
  color: var(--color-text-muted);
  text-transform: none;
}

.kk-nav-subtopic ul {
  margin-top: var(--space-1);
  padding-left: var(--space-3);
}

.kk-sidebar li + li {
  margin-top: var(--space-1);
}

.kk-sidebar a {
  display: block;
  padding: var(--space-2) var(--space-3);
  border-radius: var(--radius-small);
  text-decoration: none;
  color: var(--color-text);
  border-left: 3px solid transparent;
  overflow-wrap: break-word;
}

.kk-sidebar a:visited {
  color: var(--color-text);
}

.kk-sidebar a:hover {
  background: var(--color-blue-200-20);
}

.kk-sidebar a.is-current {
  background: var(--color-blue-200-20);
  border-left-color: var(--color-blue-600);
  color: var(--color-blue-600);
  font-weight: 600;
}

/* ==========================================================================
   Main content
   ========================================================================== */

.kk-content {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: var(--space-6);
}

.kk-content.kk-home {
  max-width: var(--content-max-width);
  margin: var(--space-8) auto;
}

.kk-content.kk-not-found {
  max-width: 640px;
  margin: var(--space-16) auto;
  text-align: center;
}

.kk-content.kk-not-found > div + div {
  margin-top: var(--space-8);
  padding-top: var(--space-8);
  border-top: 1px solid var(--color-border);
}

.kk-content img {
  max-width: 100%;
  height: auto;
  border-radius: var(--radius-small);
}

/* ==========================================================================
   Legend reference (merkintöjen selitykset)
   ========================================================================== */

.kk-legend-reference {
  border: 1px solid var(--color-border);
  border-radius: var(--radius-small);
  padding: var(--space-3) var(--space-4);
  margin-bottom: var(--space-6);
  background: var(--color-bg);
}

.kk-legend-reference summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--color-blue-600);
}

.kk-legend-reference .kk-box {
  margin-top: var(--space-3);
  border: none;
  padding: 0;
  background: none;
}

/* ==========================================================================
   Boxes: kk-box / kk-note / kk-legend
   ========================================================================== */

.kk-box {
  background: var(--color-blue-600-10);
  border-left: 4px solid var(--color-blue-600);
  border-radius: var(--radius-small);
  padding: var(--space-4);
  margin-bottom: var(--space-6);
}

.kk-box-title {
  margin: 0 0 var(--space-2) 0;
  font-weight: 700;
  color: var(--color-blue-600);
  font-size: var(--text-base-size);
}

.kk-box p:last-child {
  margin-bottom: 0;
}

.kk-note {
  background: var(--color-blue-200-20);
  border-left-color: var(--color-blue-600);
}

/* ==========================================================================
   Figures / images
   ========================================================================== */

.kk-figure {
  margin: 0 0 var(--space-6) 0;
}

.kk-figure img {
  display: block;
  border: 1px solid var(--color-border);
}

.kk-figure figcaption {
  font-size: var(--text-caption-size);
  line-height: var(--text-caption-line);
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}

/* ==========================================================================
   Tables
   ========================================================================== */

.kk-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-base-size);
  line-height: var(--text-base-line);
  margin-bottom: var(--space-6);
}

.kk-table th,
.kk-table td {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  border: 1px solid var(--color-border);
  vertical-align: top;
}

.kk-table thead th {
  background: var(--color-blue-600);
  color: #ffffff;
  font-weight: 700;
}

.kk-table tbody tr:nth-child(even) {
  background: var(--color-blue-600-10);
}

.kk-table.kk-myths thead th {
  background: var(--color-red-600);
}

.kk-table.kk-myths s {
  color: var(--color-text-muted);
  text-decoration-color: var(--color-red-600);
}

/* ==========================================================================
   Inline semantic marks (legend conventions)
   ========================================================================== */

em {
  font-style: italic;
}

u {
  text-decoration-color: var(--color-blue-600);
}

s {
  text-decoration-color: var(--color-red-600);
}

/* ==========================================================================
   Buttons & links
   ========================================================================== */

.kk-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 48px;
  padding: var(--space-3) var(--space-6);
  border-radius: var(--radius-small);
  font-size: var(--text-base-size);
  font-weight: 600;
  text-decoration: none;
  border: 2px solid transparent;
  cursor: pointer;
}

.kk-button-primary {
  background: var(--color-blue-600);
  color: #ffffff;
}

.kk-button-primary:visited {
  color: #ffffff;
}

.kk-button-primary:hover {
  background: var(--color-blue-600-80);
}

.kk-button-secondary {
  background: #ffffff;
  color: var(--color-blue-600);
  border-color: var(--color-blue-600);
}

.kk-button-secondary:visited {
  color: var(--color-blue-600);
}

.kk-button-secondary:hover {
  background: var(--color-blue-200-20);
}

.kk-button[disabled] {
  background: var(--color-blue-600-20);
  color: var(--color-text-muted);
  border-color: transparent;
  cursor: not-allowed;
}

/* ==========================================================================
   Prev / next navigation
   ========================================================================== */

.kk-prev-next {
  display: flex;
  justify-content: space-between;
  gap: var(--space-4);
  flex-wrap: wrap;
  margin-top: var(--space-8);
  padding-top: var(--space-6);
  border-top: 1px solid var(--color-border);
}

/* ==========================================================================
   Home page: hero + topic cards
   ========================================================================== */

.kk-hero {
  background: linear-gradient(180deg, var(--color-blue-200-20) 0%, var(--color-bg) 100%);
  border-bottom: 1px solid var(--color-border);
}

.kk-hero-inner {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-16) var(--space-4) var(--space-12);
}

.kk-eyebrow {
  margin: 0 0 var(--space-2) 0;
  font-size: var(--text-small-size);
  line-height: var(--text-small-line);
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--color-blue-600);
}

.kk-hero-title {
  margin: 0 0 var(--space-4) 0;
  font-size: var(--text-display-size);
  line-height: var(--text-display-line);
  font-weight: 700;
  color: var(--color-blue-600);
  max-width: 20ch;
}

.kk-hero-lead {
  margin: 0;
  font-size: var(--text-lead-size);
  line-height: var(--text-lead-line);
  color: var(--color-text);
  max-width: var(--measure-max-width);
}

.kk-home {
  width: 100%;
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-12) var(--space-4) var(--space-16);
}

.kk-card-grid {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: var(--space-6);
}

.kk-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-top: 4px solid var(--color-blue-600);
  border-radius: var(--radius);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.kk-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 8px 20px rgba(27, 27, 27, 0.08);
}

.kk-card.kk-accent-purple {
  border-top-color: var(--color-purple-600);
}

.kk-card.kk-accent-orange {
  border-top-color: var(--color-orange-400);
}

.kk-card-link {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  padding: var(--space-6);
  min-height: 160px;
  text-decoration: none;
  color: var(--color-text);
}

.kk-card-link:visited {
  color: var(--color-text);
}

.kk-card-title {
  font-size: var(--text-h4-size);
  line-height: var(--text-h4-line);
  font-weight: 700;
  color: var(--color-blue-600);
}

.kk-card-cta {
  margin-top: auto;
  padding-top: var(--space-4);
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 600;
  color: var(--color-blue-600);
}

.kk-card-arrow {
  width: 8px;
  height: 8px;
  border-right: 2px solid currentColor;
  border-bottom: 2px solid currentColor;
  transform: rotate(-45deg);
  transition: transform 0.15s ease;
}

.kk-card:hover .kk-card-arrow {
  transform: rotate(-45deg) translate(2px, -2px);
}

@media (max-width: 639px) {
  .kk-hero-inner {
    padding: var(--space-12) var(--space-4);
  }
}

/* ==========================================================================
   Footer
   ========================================================================== */

.kk-footer {
  background: var(--color-blue-600);
  color: #ffffff;
  margin-top: auto;
}

.kk-footer-inner {
  max-width: var(--content-max-width);
  margin: 0 auto;
  padding: var(--space-8) var(--space-4);
}

.kk-footer-title {
  margin: 0 0 var(--space-4) 0;
  font-size: var(--text-h4-size);
  line-height: var(--text-h4-line);
  font-weight: 700;
}

.kk-footer-links {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-2) var(--space-6);
}

.kk-footer a {
  color: #ffffff;
  text-decoration: none;
  font-size: var(--text-base-size);
}

.kk-footer a:hover {
  text-decoration: underline;
}

.kk-footer a:visited {
  color: #ffffff;
}
