/* ===================== ROOT / LAYOUT ===================== */
:root{
  --svgSize: min(92vw, 980px);
  --uiMax: 560px;

  --font-latin: Georgia, "Times New Roman", Times, serif;

  --font-cjk: "Songti SC",
              "Hiragino Mincho ProN",
              "PMingLiU",
              "MingLiU",
              "SimSun",
              "Noto Serif CJK TC",
              "Noto Serif CJK SC",
              serif;
  --font-ui:  system-ui, -apple-system, "SF Pro Text", "Segoe UI", Roboto, Arial, sans-serif;              
}

*{ box-sizing:border-box; }

body{
  margin:0;
  padding:24px;
  display:grid;
  place-items:center;
  font-family: var(--font-latin);
  background:#cccccc;
}

.wrap{
  width: var(--svgSize);
  display:grid;
  justify-items:center;
  gap:14px;
}

svg{
  width:100%;
  height:auto;
  display:block;
}

.wheelViewport{
  width: 100%;
  overflow: visible; /* desktop/tablet */
}

/* ===================== UI ===================== */
.ui{
  padding:10px;
  background:rgba(255,255,255,0.92);
  border:1px solid rgba(0,0,0,0.10);
  border-radius:14px;
  box-shadow:0 10px 30px rgba(0,0,0,0.08);

  width: max-content;
  max-width: calc(100vw - 24px);
  overflow: hidden;

  display:flex;
  flex-direction:column;
  gap:10px;
}

.row{
  display:grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap:10px;
  align-items:end;
}

label{
  font-size:13px;
  display:grid;
  gap:4px;
  min-width:0;
}

select,
.btn{
  width:auto;
  min-width:64px;
  padding:6px 6px;
  font-size:13px;
  border-radius:10px;
  border:1px solid rgba(0,0,0,0.22);
  background:#fff;
}

#result{
  margin-top:12px;
  font-weight:100;
  overflow-wrap:anywhere;
}

#meta{
  margin-top:6px;
  font-size:13px;
  color:#444;
  line-height:1.3;
}

/* Rubrik */
.title{
  text-align:center;
  font-weight:100;
  font-size:24px;
  margin-bottom:10px;
}

/* Fast rubrikhöjd så UI inte hoppar */
#result.title{
  min-height: 1em;
  line-height: 1;

  display:flex;
  align-items:center;
  justify-content:center;

  text-align:center;
  padding:4px 10px;
}

.metaWrap{
  flex: 1 1 auto;
  min-height:0;
}

.rowBottom{
  flex: 0 0 auto;
}

.exportBtn{
  grid-column:3;
  align-self:end;
  white-space:nowrap;
}

/* Buttons */
.btn{
  margin-top:10px;
  padding:10px 14px;
  border-radius:12px;
  border:1px solid #2b2b2b;
  background:#151515;
  color:#f3f3f3;
  cursor:pointer;
  font-size:16px;
}
.btn:hover{ filter:brightness(1.08); }

/* Typography mapping */
label,
#meta,
#result,
.infoText,
.infoTitle{
  font-family: var(--font-latin), var(--font-cjk);
}

.visuallyHidden{
  position:absolute;
  width:1px;
  height:1px;
  overflow:hidden;
  clip:rect(0 0 0 0);
  white-space:nowrap;
}

/* ===================== SVG STYLES ===================== */
.ringLine{
  fill:none;
  stroke:rgba(0,0,0,0.14);
  stroke-width:2;
}

.tick{
  stroke:rgba(0,0,0,0.10);
  stroke-width:1;
}

/* Emojis */
.emoji{
  font-size:48px;
  user-select:none;
  font-family:
    var(--font-cjk),
    "Apple Color Emoji",
    "Segoe UI Emoji",
    "Noto Color Emoji";
}

.cycleEmoji{
  font-size:28px;
  user-select:none;
  opacity:0.88;
  font-family:
    var(--font-cjk),
    "Apple Color Emoji",
    "Segoe UI Emoji",
    "Noto Color Emoji";
}

.emoji.selected,
.cycleEmoji.selected{
  stroke:none;
  paint-order:normal;
}

/* Yin / Yang */
.yyLine{
  stroke:rgba(0,0,0,0.85);
  stroke-width:3.2;
  stroke-linecap:round;
}
.yyLine.selected{ stroke-width:4.2; }

/* Sectors & labels */
.sector{ opacity:0.33; }

.focusBox{
  fill:#fff;
  stroke:rgba(0,0,0,0.20);
  stroke-width:3;
  rx:14;
  ry:14;
}

.labelBox{
  fill:rgba(255,255,255,0.92);
  stroke:rgba(0,0,0,0.35);
  stroke-width:1.8;
  rx:10;
  ry:10;
}

.labelText{
  font-size:12.5px;
  fill:rgba(0,0,0,0.88);
}

/* ===================== GLOBAL INFO BUTTON ===================== */
.infoBtnGlobal{
  position:fixed;
  top:12px;
  right:12px;
  z-index:1000;
  width:32px;
  height:32px;
  border-radius:999px;
  border:1px solid rgba(0,0,0,0.3);
  background:rgba(255,255,255,0.92);
  cursor:pointer;
  font:inherit;
  font-weight:800;
  line-height:1;
  display:grid;
  place-items:center;
}
.infoBtnGlobal:hover{ filter:brightness(1.06); }

/* ===================== GLOBAL INFO PANEL ===================== */
.infoPanelGlobal{
  position:fixed;
  z-index:999;
  left:50%;
  transform:translateX(-50%);
  top:60px;

  width:min(640px, calc(100vw - 24px));
  max-height:calc(100vh - 96px);
  overflow:auto;

  padding:14px;
  border-radius:16px;
  border:1px solid rgba(0,0,0,0.18);
  background:rgba(255,255,255,0.95);
  box-shadow:0 18px 40px rgba(0,0,0,0.18);
}

.infoTitle{
  font-weight:900;
  margin-bottom:8px;
}

.infoText{
  font-size:13px;
  line-height:1.4;
  color:#222;
}

.infoText p{ margin:10px 0; }

.infoText a{
  color:inherit;
  text-decoration:underline;
  text-underline-offset:2px;
}

/* Stabil “halo” utan SVG-filter */
.emoji.haloStroke,
.cycleEmoji.haloStroke{
  paint-order: stroke;
  stroke: rgba(255,255,255,0.95);
  stroke-width: 4px;
  stroke-linejoin: round;
}

/* ===================== RESPONSIVE ===================== */
/* Mobile: show only the right half + bottom sheet UI */
/* nya: mobil = smal skärm (och ev. “touch-small tablet”), men INTE iPad landscape */
@media (max-width: 540px), (max-width: 900px) and (hover: none) and (pointer: coarse){
  :root{
    --svgSize: 96vw;
    --uiMax: 680px;
  }

  html, body{
    height:100%;
    overflow:hidden;
    position:fixed;          /* iOS Safari */
    width:100%;
    overscroll-behavior:none; /* Android */
    touch-action:none;
  }

  body{
    padding:12px;
    place-items:start center;
  }

  .wrap{
    width: var(--svgSize);
    gap:10px;
    padding-bottom:0 !important;
  }

  .wheelViewport{
    position:fixed;
    inset:0;
    overflow:hidden;
    width:100vw;
    height: 100dvh;
    height: 100svh; /* fallback */
    margin:0;
    z-index:1;
  }

  .wheelViewport svg{
    width:180vw;
    max-width:none;
    transform-origin:0 50%;
    will-change:transform;

    position:absolute;
    left:0;
    top:50%;
    transform: translateY(-50%);
  }

  .ui{
    position:fixed;
    left:50%;
    transform:translateX(-50%);

    width:min(var(--uiMax), calc(100vw - 24px));
    z-index:10;

    border-radius:18px;
    background:rgba(255,255,255,0.92);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);

    bottom: calc(12px + env(safe-area-inset-bottom));
    max-height: calc(100dvh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
    max-height: calc(100svh - 24px - env(safe-area-inset-top) - env(safe-area-inset-bottom));
  }

  .row{ gap:8px; }

  label{ font-size:12px; }

  select{
    width:100%;
    padding:7px 8px;
    font-size:14px;
  }

  .title{
    font-size:17px;
    margin-bottom:8px;
  }

  #result{
    font-size:16px;
    overflow-wrap:anywhere;
    word-break:break-word;
  }

  #meta{
    font-size:12px;
    line-height:1.25;
  }

  .btn{
    width:100%;
    margin-top:10px;
  }

  .metaWrap{
    overflow:auto;
    -webkit-overflow-scrolling: touch;
  }

  /* Keep glyphs readable on mobile */
  .emoji{ font-size:30px; }
  .cycleEmoji{ font-size:16px; }
  .yyLine{ stroke-width:2.6; }
  .yyLine.selected{ stroke-width:3.4; }

  /* Info panel becomes bottom sheet too */
  .infoPanelGlobal{
    top:auto;
    bottom:12px;
    left:50%;
    transform:translateX(-50%);
    width:calc(100vw - 24px);
    max-height:calc(100vh - 96px);
    border-radius:18px;
  }
}

/* Medium: stacked, centered */
@media (min-width: 541px) and (max-width: 1099px){
  :root{
    --svgSize: min(88vw, 980px);
    --uiMax: 560px;
  }
  body{ padding:20px; }
}

/* Large: wheel + UI side-by-side */
@media (min-width: 1100px){
  :root{
    --svgSize: min(66vw, 980px);
    --uiMax: 420px;
  }

  body{
    padding:28px;
    place-items:center;
  }

  .wrap{
    width: calc(var(--svgSize) + var(--uiMax) + 28px);
    grid-template-columns: var(--svgSize) min(100%, var(--uiMax));
    grid-auto-flow: column;
    align-items:center;
    justify-items:center;
    gap:28px;
  }

  .ui{
    width: min(100%, var(--uiMax));
    margin-top:0;
  }
}

@media (max-width: 900px) and (orientation: landscape) and (hover: none) and (pointer: coarse){
  .ui{
    padding:8px;
    gap:8px;
  }
  .title{
    font-size:16px;
    margin-bottom:6px;
  }
  #meta{
    font-size:11px;
    line-height:1.2;
  }
  .btn{
    margin-top:8px;
    padding:9px 12px;
    font-size:15px;
  }
}