/* ════════════════════════════════════════
   MOBILE STYLES (max-width: 767px)
════════════════════════════════════════ */
@media (max-width: 767px) {
  #mobile-view { display: block; }
  html, body {
    width: 100%; height: 100vh;
    display: flex; align-items: flex-start; justify-content: center;
    background: #fff;
    font-family: 'NicoClean', monospace;
    overflow: hidden;
    overscroll-behavior: none;
  }

  #device {
    position: relative;
    width: 430px;
    /* height is set inline by mScaleDevice() so layout-height * scale = innerHeight */
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    background: #fff;
    transform-origin: top center;
  }

  /* ── SVG frame slices ── */
  .frame-top {
    width: 430px;
    height: 105px;
    flex: 0 0 105px;
    display: block;
    pointer-events: none;
    position: relative;
    z-index: 10;
  }
  .frame-mid {
    width: 430px;
    flex: 1 1 0;
    min-height: 0;
    margin-top: -2px;
    margin-bottom: -2px;
    display: block;
    pointer-events: none;
    position: relative;
    z-index: 10;
  }
  .frame-bottom {
    position: relative;
    width: 430px;
    height: 295px;
    flex: 0 0 295px;
  }
  .frame-bottom-art {
    position: absolute;
    inset: 0;
    width: 430px;
    height: 295px;
    pointer-events: none;
    z-index: 10;
  }

  /* ── Page bar ── */
  #page-bar {
    position: absolute;
    left: 25px; top: 45px;
    width: 380px; height: 50px;
    z-index: 11;
    pointer-events: none;
    display: flex;
    align-items: center;
  }
  #page-title {
    position: absolute;
    left: 52px; top: 19px;
    font-size: 15px;
    line-height: 1;
    color: #989898;
    text-transform: uppercase;
    white-space: nowrap;
  }

  /* ── Screen content area (confined within mid slice, 10px inset top/bottom) ── */
  #screen-content {
    position: absolute;
    left: 35px;
    top: 115px;       /* top slice (105) + 10px padding */
    bottom: 305px;    /* btm slice (295) + 10px padding */
    width: 360px;
    background: #fff;
    overflow: hidden;
    z-index: 1;
  }

  /* ── TV static ── */
  #m-static-canvas {
    display: none;
    position: absolute;
    inset: 0;
    width: 100%; height: 100%;
    z-index: 31;
  }

  /* ── Pages ── */
  .m-page {
    position: absolute;
    top: 0; left: 0; bottom: 0;
    right: 0;
    overflow-y: auto;
    overflow-x: hidden;
    opacity: 0;
    pointer-events: none;
    overscroll-behavior: contain;
    z-index: 3;
  }
  .m-page.active {
    opacity: 1;
    pointer-events: all;
  }

  .scroll-track {
    position: absolute;
    right: 2px; top: 0; bottom: 0;
    width: 4px;
    background: #f0f0f0;
    z-index: 9;
    pointer-events: none;
    border-radius: 2px;
  }
  .scroll-thumb {
    position: absolute;
    right: 0;
    width: 4px;
    background: #bbb;
    border-radius: 2px;
    min-height: 20px;
  }
  .m-page { scrollbar-width: none; scrollbar-color: #bbb #f0f0f0; }
  .m-page::-webkit-scrollbar { display: none; }

  .m-page-inner { padding: 10px 26px 10px 2px; }
  /* Padding is asymmetric: NicoClean's glyph sits in the upper half of its line-box,
     so extra padding-top + reduced padding-bottom shifts the visible text to the centre. */
  .m-tag { display: inline-flex; align-items: center; justify-content: center; padding: 4px 6px 0; background: rgba(0,133,117,0.1); color: #008575; font-size: 12px; line-height: 1; border: 1px solid rgba(0,133,117,0.3); margin-right: 3px; }
  .m-card {
    border: 1.5px solid #e0e0e0;
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.15s;
    height: 438px;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }
  .m-card:hover, .m-card.focused { border-color: #008575; border-width: 3px; background: rgba(0,133,117,0.02); }
  .m-card-thumb {
    width: 100%;
    height: auto;
    aspect-ratio: 8 / 5;
    flex-shrink: 0;
    background: repeating-linear-gradient(45deg,#e8e8e8 0,#e8e8e8 6px,#f0f0f0 6px,#f0f0f0 12px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #bbb;
    border-bottom: 1.5px solid #e0e0e0;
    position: relative;
  }
  .m-card-thumb.dark { background: #1a1a1a; }
  .m-card-body {
    flex: 1;
    min-height: 0;
    padding: 16px 12px 10px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
  }
  .m-card-info-top { display: flex; flex-direction: column; }
  .m-card-title { font-size: 12px; color: #1a1a1a; line-height: 1.3; }
  .m-card-date { font-size: 12px; color: #989898; margin-top: 2px; }
  .m-card-pill {
    align-self: flex-start;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: #e8e8e8;
    color: #555;
    font-size: 12px;
    line-height: 1;
    letter-spacing: 0.05em;
    /* Asymmetric padding: NicoClean glyph offset compensation */
    padding: 5px 8px 1px;
    border-radius: 999px;
    margin-top: 8px;
  }
  .m-card-desc { font-size: 12px; color: #555; line-height: 1.35; margin-top: 16px; }
  .m-card-tags { display: flex; gap: 4px; flex-wrap: wrap; }
  .m-card-meta { font-size: 12px; color: #989898; }
  .m-row-card { border: 1.5px solid #e0e0e0; margin-bottom: 7px; cursor: pointer; display: flex; align-items: center; gap: 10px; padding: 9px 11px; transition: border-color 0.15s; min-height: 90px; }
  .m-row-card:hover, .m-row-card.focused { border-color: #008575; border-width: 3px; background: rgba(0,133,117,0.02); }
  /* NicoClean glyph offset compensation: padding-top > padding-bottom shifts the
     centred text ~2px down so it sits at the visual centre of the badge. */
  .m-row-icon { width: 38px; height: 38px; background: #008575; display: flex; align-items: center; justify-content: center; color: #fff; font-size: 12px; flex-shrink: 0; box-sizing: border-box; padding: 4px 0 0; }
  .m-row-date { font-size: 12px; color: #008575; white-space: nowrap; min-width: 48px; flex-shrink: 0; }
  .m-row-info { flex: 1; min-width: 0; }
  .m-status { display: inline-flex; align-items: center; justify-content: center; font-size: 12px; line-height: 1; padding: 4px 5px 0; flex-shrink: 0; }
  .m-status.live { background: rgba(0,133,117,0.12); color: #008575; border: 1px solid rgba(0,133,117,0.4); }
  .m-status.soon { background: rgba(0,0,0,0.05); color: #888; border: 1px solid #ccc; }
  .m-play { width: 0; height: 0; border-top: 9px solid transparent; border-bottom: 9px solid transparent; border-left: 14px solid #008575; position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%); }

  /* ── Detail overlay ── */
  #m-detail {
    position: absolute;
    inset: 0;
    background: #fff;
    z-index: 20;
    transform: translateX(100%);
    transition: transform 250ms cubic-bezier(0.4,0,0.2,1);
    display: flex; flex-direction: column;
    overflow: hidden;
  }
  #m-detail.open { transform: translateX(0); }
  #m-detail-back { display: flex; align-items: center; gap: 8px; padding: 12px 14px 30px; cursor: pointer; color: #989898; font-size: 12px; flex-shrink: 0; }
  #m-detail-back:hover { color: #008575; }
  .m-back-arrow { width: 8px; height: 8px; background: currentColor; clip-path: polygon(0% 50%, 100% 0%, 100% 100%); flex-shrink: 0; }
  #m-detail-content { flex: 1; overflow-y: auto; padding: 12px 14px 10px; display: flex; flex-direction: column; gap: 10px; overscroll-behavior: contain; }
  .m-detail-hero { width: 100%; height: 80px; background: repeating-linear-gradient(45deg,#e8e8e8 0,#e8e8e8 6px,#f0f0f0 6px,#f0f0f0 12px); display: flex; align-items: center; justify-content: center; font-size: 12px; color: #bbb; border: 1.5px solid #e0e0e0; }
  .m-detail-hero.dark { background: #1a1a1a; color: #555; position: relative; }
  /* Remove placeholder border/bg when a real image is rendered inside; let image set height */
  .m-detail-hero:has(img) { border: 0; background: none; height: auto; }
  .m-detail-title { font-size: 17px; color: #1a1a1a; line-height: 1.2; }
  .m-detail-divider { width: 28px; height: 2px; background: #008575; }
  .m-detail-body { font-size: 12px; color: #555; line-height: 1.7; }
  .m-detail-body p { margin-bottom: 8px; }
  /* Same base.css reset fix as desktop — use inside position to keep bullets from bleeding left */
  .m-detail-body ul,
  .m-detail-body ol  { padding-left: 1.2em; margin-bottom: 8px; }
  .m-detail-body li  { list-style-position: inside; margin-bottom: 3px; }
  .m-placeholder { width: 100%; height: 70px; background: repeating-linear-gradient(45deg,#e8e8e8 0,#e8e8e8 6px,#f0f0f0 6px,#f0f0f0 12px); border: 1.5px solid #e0e0e0; display: flex; align-items: center; justify-content: center; font-size: 12px; color: #bbb; }

  /* ── Page menu overlay ── */
  #m-menu {
    position: absolute;
    inset: 0;
    background: rgba(40,43,58,0.96);
    z-index: 25;
    display: flex; flex-direction: column;
    padding: 20px 18px;
    gap: 6px;
    opacity: 0; pointer-events: none;
    transition: opacity 0.2s ease;
  }
  #m-menu.open { opacity: 1; pointer-events: all; }
  .m-menu-item { padding: 13px 14px; border: 1.5px solid rgba(255,255,255,0.15); color: #989898; font-size: 17px; cursor: pointer; transition: background 0.1s, color 0.1s; }
  .m-menu-item:hover, .m-menu-item.active { background: rgba(0,133,117,0.2); color: #fff; border-color: #008575; }
  #m-menu-close { position: absolute; top: 14px; right: 18px; color: #989898; font-size: 20px; cursor: pointer; }
  #m-menu-close:hover { color: #fff; }

  /* ── About Me (mobile) ── */
  .m-about {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 14px 24px 30px 4px;
  }
  /* Hero */
  .m-about-hero {
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
  }
  .m-about-avatar {
    width: 63%;
    max-width: 164px;
    height: auto;
    align-self: center;
    margin-bottom: 14px;
    background: transparent;
  }
  .m-about-name {
    font-size: 32px;
    line-height: 1;
    color: #1a1a1a;
    letter-spacing: -0.01em;
    text-align: center;
  }
  .m-about-job-title {
    font-size: 12px;
    color: #008575;
    letter-spacing: 0.14em;
    text-transform: uppercase;
    margin-top: 6px;
    text-align: center;
  }
  .m-about-divider {
    width: 32px;
    height: 2px;
    background: #008575;
    margin-top: 10px;
  }
  .m-about-notice {
    display: flex;
    align-items: center;
    justify-content: center;
    background: #e8e8e8;
    color: #555;
    font-size: 12px;
    line-height: 1.3;
    letter-spacing: 0.05em;
    /* NicoClean glyph offset compensation */
    padding: 10px 12px 6px;
    border-radius: 999px;
    text-align: center;
    margin-top: -6px;
    margin-bottom: -6px;
  }
  /* Intro paragraphs */
  .m-about-intro-text {
    display: flex;
    flex-direction: column;
    gap: 8px;
    text-align: center;
  }
  .m-about-intro-para {
    font-size: 13px;
    line-height: 1.6;
    color: #555;
    margin: 0;
  }
  /* Social row */
  .m-about-social-row {
    display: flex;
    gap: 8px;
  }
  .m-about-social-btn {
    flex: 1;
    aspect-ratio: 1 / 1;
    min-height: 50px;
    border: 1.5px solid #e0e0e0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: #777;
    text-decoration: none;
    transition: border-color 0.15s, color 0.15s, background 0.15s;
    cursor: pointer;
  }
  .m-about-social-btn svg { width: 40px; height: 40px; } /* 50px button − 5px each side */
  .m-about-social-btn:hover, .m-about-social-btn:active {
    border-color: #008575;
    color: #008575;
    background: rgba(0,133,117,0.04);
  }
  /* Section headers (title above teal underline) */
  .m-about-section-header {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 4px;
  }
  /* Extra spacing between "screens" — equivalent of 2 line breaks */
  .m-about-social-row + .m-about-section-header,
  .m-about-skills-list + .m-about-section-header {
    margin-top: 36px;
  }
  .m-about-section-title {
    font-size: 12px;
    color: #989898;
    text-transform: uppercase;
    letter-spacing: 0.12em;
  }
  .m-about-section-line {
    width: 28px;
    height: 2px;
    background: #008575;
  }
  /* Donut */
  .m-about-donut-wrap {
    display: flex;
    justify-content: center;
    padding: 6px 0;
  }
  .m-about-donut {
    width: 100%;
    max-width: 320px;
    height: auto;
    overflow: visible;
  }
  .m-about-donut-slice { cursor: help; }
  .m-about-donut-label {
    font-family: 'NicoClean', monospace;
    font-size: 12px;
    fill: #1a1a1a;
    pointer-events: none;
  }
  .m-about-donut-label-yrs {
    font-size: 12px;
    fill: #989898;
  }
  /* Skills list */
  .m-about-skills-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
  }
  .m-about-skill-row {
    display: flex;
    align-items: center;
    /* 10px between axis label → circles AND between circles → year label */
    gap: 10px;
  }
  .m-about-skill-name {
    color: #1a1a1a;
    width: 88px;
    flex-shrink: 0;
    /* Block-level flex container — inner <span> holds the text so it can be
       reliably centred (and supports text-overflow if it ever needs to clip) */
    display: flex;
    align-items: center;
    height: 14px;
  }
  .m-about-skill-name > span {
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    width: 100%;
    /* NicoClean's painted glyph sits in the upper half of its line-box —
       nudge down so the visible centre aligns with the pip centre. */
    transform: translateY(2px);
  }
  .m-about-skill-bars {
    display: flex;
    flex-wrap: nowrap;
    gap: 5px;
    flex-shrink: 1;
  }
  .m-about-skill-pip {
    width: 14px;
    height: 14px;
    display: inline-block;
    flex-shrink: 0;
    background: #008575;
    border-radius: 50%;
  }
  .m-about-skill-level {
    color: #555;
    /* Right-side gap is provided by the row's 10px gap above */
    margin-left: 0;
    display: flex;
    align-items: center;
    height: 14px;
  }
  .m-about-skill-level > span {
    font-size: 12px;
    line-height: 1;
    white-space: nowrap;
    /* Same NicoClean metrics compensation */
    transform: translateY(2px);
  }
  /* Works list (single column) */
  .m-about-works-list {
    display: flex;
    flex-direction: column;
    gap: 22px;
  }
  .m-about-works-list .m-about-work {
    border: 1.5px solid #e0e0e0;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s;
  }
  .m-about-works-list .m-about-work:hover,
  .m-about-works-list .m-about-work.focused {
    border-color: #008575;
    border-width: 3px;
  }
  .m-about-work-thumb {
    width: 100%;
    height: 154px;
    background: repeating-linear-gradient(45deg,#e8e8e8 0,#e8e8e8 8px,#f0f0f0 8px,#f0f0f0 16px);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 12px;
    color: #aaa;
    border-bottom: 1.5px solid #e0e0e0;
  }
  .m-about-work-info {
    padding: 20px 12px 8px; /* top 20px = gap between image and title */
    display: flex;
    flex-direction: column;
    gap: 4px;
  }
  .m-about-work-title {
    font-size: 13px;
    color: #1a1a1a;
    line-height: 1.3;
  }
  .m-about-work-date {
    font-size: 12px;
    color: #989898;
  }
  .m-about-work-desc {
    font-size: 12px;
    color: #555;
    line-height: 1.45;
    margin-top: 20px;
  }
  .m-about-work-tags {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    margin-top: 20px;
  }

  /* Navigation hint banner */
  .m-about-nav-hint {
    margin-top: 32px;
    padding: 14px 16px;
    background: #008575;
    color: #fff;
    font-size: 12px;
    line-height: 1.5;
    text-align: center;
    border-radius: 4px;
  }

  /* ── D-pad (anchored inside .frame-bottom) ── */
  #dpad {
    position: absolute;
    left: 25px; top: 43px;
    width: 160px; height: 160px;
    z-index: 11;
  }
  #dpad-up, #dpad-down, #dpad-left, #dpad-right {
    position: absolute;
    width: 54px; height: 54px;
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    touch-action: manipulation;
    z-index: 7;
  }
  #dpad-up    { left: 53px; top: 18px; }
  #dpad-down  { left: 53px; top: 88px; }
  #dpad-left  { left: 18px;  top: 53px; }
  #dpad-right { left: 88px; top: 53px; }

  /* ── Action buttons (anchored inside .frame-bottom) ── */
  #action-buttons {
    position: absolute;
    left: 232px; top: 72px;
    width: 165px; height: 136px;
    z-index: 11;
  }
  #btn-cancel, #btn-confirm {
    position: absolute;
    width: 70px; height: 70px;
    cursor: pointer;
    user-select: none;
    touch-action: manipulation;
    -webkit-tap-highlight-color: transparent;
    display: block;
  }
  #btn-cancel  { left: 24px; top: 42px; }
  #btn-confirm { left: 92px; top: 4px; }

  /* ── Home / Contact buttons ── */
  /* Home / Contact SVG buttons */
  #home-btn-wrap, #contact-btn-wrap {
    position: absolute;
    width: 70px; height: 32px;
    z-index: 11;
    cursor: pointer;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    display: block;
  }
  #home-btn-wrap    { left: 140px; top: 205px; }
  #contact-btn-wrap { left: 215px; top: 199px; }

  /* ── Trainings form ── */
  #m-page-trainings { display: flex; flex-direction: column; overflow: hidden; }
  #m-page-trainings .m-page-inner { flex: 1; min-height: 0; display: flex; flex-direction: column; overflow: hidden; }
  .m-trainings-intro { font-size: 12px; color: #555; line-height: 1.45; margin: 0 4px 20px 4px; }
  .m-contact-form { display: flex; flex-direction: column; gap: 12px; padding: 0 4px; flex: 1; min-height: 0; }
  .m-contact-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
  .m-contact-row .m-contact-field { min-width: 0; }
  .m-contact-row input { width: 100%; box-sizing: border-box; min-width: 0; }
  .contact-hp { position: absolute !important; left: -9999px !important; width: 1px !important; height: 1px !important; opacity: 0 !important; }
  .m-contact-field { display: flex; flex-direction: column; gap: 2px; position: relative; }
  .m-contact-field:has(textarea) { flex: 1; min-height: 0; }
  .m-contact-field > span { font-size: 11px; color: #989898; letter-spacing: 0.08em; text-transform: uppercase; }
  .m-contact-field input,
  .m-contact-field textarea {
    font-family: 'NicoClean', monospace; font-size: 13px; color: #1a1a1a;
    padding: 6px 10px; border: 1.5px solid #e0e0e0; background: #fff;
    outline: none; transition: border-color 0.15s; -webkit-appearance: none;
  }
  .m-contact-field textarea { resize: none; line-height: 1.5; flex: 1; min-height: 0; }
  .m-contact-field input:focus,
  .m-contact-field textarea:focus { border-color: #008575; }
  .m-contact-foot { display: flex; flex-direction: column; gap: 6px; align-items: stretch; margin-top: 4px; }
  .m-contact-status { font-size: 11px; color: #c44; min-height: 12px; }
  .m-contact-status.ok { color: #008575; }
  .m-contact-submit {
    font-family: 'NicoClean', monospace; font-size: 13px; letter-spacing: 0.08em;
    padding: 9px; background: #008575; color: #fff; border: 0; cursor: pointer;
    -webkit-tap-highlight-color: transparent;
  }
  .m-contact-submit:active { background: #006b5d; }
  .m-contact-submit:disabled { background: #aaa; }

  /* Toast — confirmation that auto-dismisses after 2s */
  .m-contact-toast {
    position: absolute;
    top: 50%; left: 50%;
    transform: translate(-50%, -50%) scale(0.96);
    background: #008575; color: #fff;
    font-family: 'NicoClean', monospace; font-size: 13px; letter-spacing: 0.06em;
    padding: 12px 20px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.25);
    z-index: 100;
    opacity: 0;
    transition: opacity 250ms ease, transform 250ms ease;
    pointer-events: none;
    white-space: nowrap;
  }
  .m-contact-toast.show { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}
