<style>
    /* --- GLOBAL RESETS --- */
    html {
      margin: 0 !important;
      padding: 0 !important;
      background-color: #1e293b !important;
      overscroll-behavior-y: none;
    }
    
    /* --- APP SHELL & CORE STYLES --- */
    * { box-sizing: border-box; }
    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
      background-color: #0f172a;
      color: #f8fafc;
      margin: 0;
      padding: 0;
      display: flex;
      flex-direction: column;
      min-height: 100vh;
      padding-bottom: 60px;
    }

    #webview-warning-banner {
      display: none;
      background: #dc2626;
      color: #ffffff;
      padding: 10px 12px;
      font-size: 0.75rem;
      line-height: 1.4;
      font-weight: 600;
      text-align: center;
      border-bottom: 2px solid #991b1b;
      position: sticky;
      top: 0;
      z-index: 10001;
    }

    #a2hs-prompt-banner {
      display: none;
      background: #1e293b;
      border: 1px solid #38bdf8;
      color: #f8fafc;
      padding: 8px 12px;
      border-radius: 8px;
      margin-bottom: 10px;
      font-size: 0.72rem;
      line-height: 1.4;
      align-items: center;
      justify-content: space-between;
      gap: 8px;
    }

    header.app-header {
      background: #1e293b;
      padding-top: calc(10px + env(safe-area-inset-top, 0px));
      padding-right: 14px;
      padding-bottom: 10px;
      padding-left: 14px;
      border-bottom: 1px solid #334155;
      border-top: none !important;
      display: flex;
      align-items: center;
      justify-content: space-between;
      gap: 12px;
      min-height: 72px;
    }

    .header-brand { 
      display: flex; 
      align-items: center; 
      gap: 12px; 
      flex: 1;
      min-width: 0;
    }

    header.app-header img { 
      width: 58px; 
      height: 58px; 
      border-radius: 10px; 
      object-fit: contain; 
      flex-shrink: 0; 
    }

    header.app-header h1 { 
      margin: 0; 
      font-size: 0.88rem; 
      line-height: 1.2;
      color: #38bdf8; 
      letter-spacing: 0.3px; 
      text-transform: uppercase; 
      text-align: left; 
    }

    header.app-header .sub-title { 
      display: block; 
      font-size: 0.62rem; 
      color: #94a3b8; 
      font-weight: normal; 
      text-align: left; 
      margin-top: 2px;
    }

    .header-actions {
      display: flex;
      flex-direction: column;
      gap: 6px;
      flex-shrink: 0;
    }

    .header-actions button {
      border: none;
      padding: 7px 12px;
      border-radius: 6px;
      font-weight: 800;
      font-size: 0.68rem;
      cursor: pointer;
      white-space: nowrap;
      text-align: center;
      line-height: 1;
      letter-spacing: 0.3px;
    }

    .btn-specs {
      background: #0284c7;
      color: #ffffff;
    }

    .btn-emergency {
      background: #dc2626;
      color: #ffffff;
      box-shadow: 0 2px 6px rgba(220, 38, 38, 0.4);
    }

    /* LANGUAGE TOGGLE STYLES */
    .lang-toggle-wrap {
      display: flex;
      gap: 2px;
      background: #0f172a;
      border-radius: 6px;
      padding: 2px;
      border: 1px solid #334155;
      justify-content: center;
    }
    .btn-lang {
      background: none;
      border: none;
      color: #94a3b8;
      font-size: 0.62rem;
      font-weight: 800;
      padding: 4px 8px;
      border-radius: 4px;
      cursor: pointer;
    }
    .btn-lang.active {
      background: #38bdf8;
      color: #0f172a;
    }

    main#app-content { flex: 1; padding: 8px; max-width: 800px; margin: 0 auto; width: 100%; overflow-x: hidden; }

    /* TAB & SUB-TAB NAVIGATION */
    .tab-content { display: none; }
    .tab-content.active { display: block; }

    .sub-tab-content { display: none; }
    .sub-tab-content.active { display: block; }

    .rule-nested-content { display: none; }
    .rule-nested-content.active { display: block; }

    .segmented-control {
      display: flex;
      background: #1e293b;
      border: 1px solid #334155;
      border-radius: 8px;
      padding: 3px;
      margin-bottom: 10px;
      overflow-x: auto;
      -webkit-overflow-scrolling: touch;
    }
    .sub-tab-btn {
      flex: 1;
      background: none;
      border: none;
      color: #94a3b8;
      padding: 8px 6px;
      font-size: 0.72rem;
      font-weight: 700;
      border-radius: 6px;
      cursor: pointer;
      text-align: center;
      white-space: nowrap;
    }
    .sub-tab-btn.active { background: #38bdf8; color: #0f172a; }

    .nested-segmented-control {
      background: #0f172a;
      border: 1px solid #334155;
      border-radius: 6px;
      margin-bottom: 12px;
    }
    .nested-tab-btn {
      color: #94a3b8;
      font-size: 0.7rem;
      padding: 6px 4px;
    }
    .nested-tab-btn.active {
      background: #4673a6;
      color: #ffffff;
    }

    nav.tab-bar {
      position: fixed;
      bottom: 0; left: 0; right: 0;
      height: 60px;
      background: #1e293b;
      border-top: 1px solid #334155;
      display: flex;
      justify-content: space-around;
      align-items: center;
      z-index: 9999;
    }
    .tab-btn {
      background: none; border: none; color: #94a3b8;
      display: flex; flex-direction: column; align-items: center;
      font-size: 0.65rem; font-weight: 600; cursor: pointer; padding: 4px; width: 20%;
    }
    .tab-btn .tab-icon { font-size: 1.1rem; margin-bottom: 1px; }
    .tab-btn.active { color: #38bdf8; }

    footer.app-footer {
      background: #0f172a; padding: 12px; text-align: center;
      border-top: 1px solid #1e293b; font-size: 0.75rem; color: #94a3b8; margin-top: 16px;
    }
    footer.app-footer a { color: #38bdf8; text-decoration: none; margin: 0 4px; }

    /* CARDS & FORMS */
    .tool-card {
      background: #ffffff; color: #333; border-radius: 10px; padding: 12px; 
      margin-bottom: 12px; border: 1px solid #334155; box-shadow: 0 4px 15px rgba(0,0,0,0.15);
      width: 100%; box-sizing: border-box;
    }
    .tool-card h2, .tool-card h3 { margin: 0 0 6px 0; color: #4673a6; font-size: 1.1rem; text-align: center; }

    /* TAB 1: DECISION MATRIX */
    #risk-calculator { 
      font-family: inherit; border: 1px solid #334155; border-radius: 10px; 
      padding: 10px; background: #ffffff; color: #333; box-shadow: 0 4px 15px rgba(0,0,0,0.15); 
    }
    .risk-header { text-align: center; color: #2c3e50; margin-bottom: 8px; }
    .risk-header h2 { margin: 0; color: #4673a6; font-size: 1.05rem; }
    .risk-section { margin-bottom: 6px; padding-bottom: 6px; border-bottom: 1px dashed #eee; }
    .risk-section-title { font-size: 0.7rem; color: #84b480; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 3px; display: block; }
    .risk-row { margin-bottom: 4px; }
    .risk-label { font-weight: 600; color: #34495e; margin-bottom: 2px; font-size: 0.75rem; display: block; }
    .risk-options { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
    button.risk-btn { 
      width: 100%; padding: 4px 2px; border: 1px solid #e0e0e0 !important; 
      background-color: #f8f9fa !important; color: #333 !important; cursor: pointer; 
      border-radius: 5px; display: flex; flex-direction: column; align-items: center; justify-content: center; 
      text-align: center; min-height: 38px; margin: 0 !important;
    }
    .btn-title { display: block; font-weight: 700; font-size: 0.7rem; margin-bottom: 1px; line-height: 1; }
    .btn-desc { display: block; font-size: 0.6rem; color: #7f8c8d; line-height: 1; }
    button.risk-btn.selected { transform: translateY(-1px); border-color: transparent !important; }
    button.risk-btn.selected[data-val="0"] { background-color: #84b480 !important; } 
    button.risk-btn.selected[data-val="0"] * { color: white !important; }
    button.risk-btn.selected[data-val="1"] { background-color: #f4c542 !important; } 
    button.risk-btn.selected[data-val="1"] .btn-title { color: #2c3e50 !important; }
    button.risk-btn.selected[data-val="1"] .btn-desc { color: #444 !important; }
    button.risk-btn.selected[data-val="2"] { background-color: #d9534f !important; } 
    button.risk-btn.selected[data-val="2"] * { color: white !important; }
    .mitigation-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; width: 100%; }
    .mitigation-btn { padding: 6px 4px; border: 1px dashed #4673a6; background: #f0f7ff; cursor: pointer; border-radius: 5px; text-align: center; font-size: 0.7rem; color: #4673a6; }
    .mitigation-btn.active { background: #4673a6; color: white; border-style: solid; }
    .mitigation-btn.disabled { opacity: 0.5; background: #eee; border-color: #ccc; color: #999; }
    #risk-result { margin-top: 8px; padding: 8px; text-align: center; border-radius: 6px; background: #f1f3f5; color: #7f8c8d; border: 1px dashed #d1d9e6; }
    #verdict-title { font-size: 1.05rem; font-weight: 800; display: block; margin-bottom: 2px; text-transform: uppercase; }
    .warning-note { display: block; margin-top: 4px; padding-top: 4px; border-top: 1px solid rgba(255,255,255,0.3); font-size: 0.7rem; font-style: italic; }

    /* CHECKLIST & BRIEFING STYLES */
    .checklist-item { 
      display: flex; 
      align-items: flex-start; 
      gap: 8px; 
      padding: 8px; 
      background: #f8fbff; 
      border: 1px solid #d1d9e6; 
      border-radius: 6px; 
      margin-bottom: 6px; 
      font-size: 0.8rem; 
      color: #333;
      word-break: break-word;
      overflow-wrap: break-word;
    }
    .checklist-item label { flex: 1; min-width: 0; }
    .checklist-item input[type="checkbox"] { width: 18px; height: 18px; margin-top: 1px; accent-color: #4673a6; flex-shrink: 0; }
    
    .ref-table { width: 100%; border-collapse: collapse; font-size: 0.75rem; margin-top: 6px; }
    .ref-table th { background: #f0f7ff; color: #4673a6; text-align: left; padding: 6px 8px; border-bottom: 2px solid #d1d9e6; font-weight: bold; }
    .ref-table td { padding: 6px 8px; border-bottom: 1px solid #e2e8f0; color: #333; vertical-align: top; }

    /* EMERGENCY CARDS */
    .emergency-card { 
      background: #fff5f5; 
      border: 1px solid #feb2b2; 
      border-radius: 8px; 
      padding: 14px 16px; 
      margin-bottom: 16px; 
      color: #2d3748; 
      box-shadow: 0 2px 6px rgba(0,0,0,0.05);
    }
    .emergency-card h4 { color: #c53030; font-size: 1rem; margin: 0 0 8px 0; font-weight: 800; border-bottom: 1px solid #fecaca; padding-bottom: 4px; }
    .emergency-card p { margin: 0; font-size: 0.85rem; line-height: 1.6; color: #1a202c; }

    /* TAB 2: ANCHOR & TIDES */
    .input-group { margin-bottom: 12px; }
    .input-label { display: block; font-weight: 700; color: #34495e; margin-bottom: 4px; font-size: 0.8rem; }
    .input-row { display: flex; gap: 8px; align-items: center; }
    .range-wrap { flex-grow: 1; }
    input[type=range] { width: 100%; cursor: pointer; accent-color: #4673a6; }
    .number-display { width: 55px; padding: 4px; border: 1px solid #d1d9e6; border-radius: 5px; text-align: center; font-weight: bold; color: #4673a6; background: #f8f9fa; font-size: 0.85rem; }
    .cond-options { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 4px; }
    button.cond-btn { width: 100%; padding: 6px 2px; border: 1px solid #e0e0e0; background-color: #f8f9fa; color: #333; cursor: pointer; border-radius: 5px; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; min-height: 42px; }
    .cond-title { font-weight: 700; font-size: 0.7rem; margin-bottom: 1px; }
    .cond-desc { font-size: 0.6rem; color: #7f8c8d; }
    button.cond-btn.selected { border-color: transparent; color: white; }
    button.cond-btn.selected[data-scope="3"] { background-color: #84b480; }
    button.cond-btn.selected[data-scope="5"] { background-color: #f4c542; }
    button.cond-btn.selected[data-scope="7"] { background-color: #d9534f; }
    button.cond-btn.selected * { color: white !important; }
    #anchor-result { margin-top: 12px; padding: 12px; background: #4673a6; color: white; border-radius: 6px; text-align: center; }
    .res-big { font-size: 1.8rem; font-weight: 800; line-height: 1; }
    .res-label { font-size: 0.75rem; opacity: 0.9; text-transform: uppercase; letter-spacing: 0.5px; }
    .res-detail { font-size: 0.7rem; margin-top: 4px; opacity: 0.85; font-style: italic; }

    .anchor-guide-box { background: #f8fbff; border-left: 4px solid #4673a6; padding: 10px; margin-top: 10px; border-radius: 0 6px 6px 0; font-size: 0.75rem; color: #334155; }
    .anchor-guide-box h4 { margin: 0 0 6px 0; color: #4673a6; font-size: 0.85rem; }
    .anchor-guide-box ol { margin: 0; padding-left: 18px; }
    .anchor-guide-box li { margin-bottom: 4px; line-height: 1.3; }

    .tide-input-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
    .tide-input-group label { font-size: 0.75rem; font-weight: bold; margin-bottom: 2px; color: #555; display: block; }
    .tide-input-group input { width: 100%; padding: 6px; border: 1px solid #ccc; border-radius: 5px; font-size: 0.9rem; background: #fcfcfc; }
    #tide-results { background: #f0f0f7; border-radius: 6px; padding: 8px 12px; }
    .tide-row { display: flex; justify-content: space-between; padding: 4px 0; border-bottom: 1px solid #d1d9e6; font-size: 0.8rem; color: #333; }
    .tide-row:last-child { border-bottom: none; }
    .tide-hour { font-weight: bold; color: #4673a6; }
    .tide-summary { margin-top: 8px; font-size: 0.8rem; text-align: center; padding-top: 6px; border-top: 1px dashed #4673a6; color: #333; }

    /* TAB 3: ENGINE & CHECKS */
    #wobble-widget { font-family: inherit; border: 2px solid #4673a6; border-radius: 10px; padding: 12px; background: #ffffff; color: #333; box-shadow: 0 4px 15px rgba(0,0,0,0.15); }
    .wobble-header { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; border-bottom: 1px solid #d1d9e6; padding-bottom: 6px; }
    .wobble-header h3 { margin: 0; color: #4673a6; font-size: 1rem; }
    .wobble-icon { background: #4673a6; color: white; border-radius: 50%; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; font-weight: bold; font-size: 0.85rem; flex-shrink: 0; }
    .wobble-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; }
    .wobble-item { background: #f8fbff; border: 1px solid #d1d9e6; border-radius: 6px; padding: 8px 4px; text-align: center; }
    .wobble-letter { display: block; font-size: 1.2rem; font-weight: 900; color: #4673a6; }
    .wobble-title { display: block; font-weight: 700; font-size: 0.7rem; color: #2c3e50; text-transform: uppercase; margin-bottom: 2px; }
    .wobble-desc { display: block; font-size: 0.6rem; color: #7f8c8d; line-height: 1.1; }

    /* TAB 4: PLANNING & CHART */
    .nav-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 8px; width: 100%; }
    .nav-grp { display: flex; flex-direction: column; gap: 2px; width: 100%; min-width: 0; }
    .nav-grp label { font-size: 0.65rem; color: #555; font-weight: bold; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .nav-grp input, .nav-grp select { padding: 6px 4px; border: 1px solid #ccc; border-radius: 4px; font-size: 0.8rem; background: #fff; width: 100%; box-sizing: border-box; }
    .nav-calc-btn { width: 100%; background: #4673a6; color: white; border: none; padding: 10px; border-radius: 6px; font-weight: bold; cursor: pointer; font-size: 0.9rem; margin-top: 6px; }
    .nav-res-row { display: flex; justify-content: space-between; padding: 5px 0; border-bottom: 1px solid #eee; font-size: 0.8rem; align-items: center; }
    .nav-res-val { font-weight: bold; color: #2c5282; font-family: monospace; font-size: 0.95rem; }

    .aw-chart-container { border: 1px solid #334155; border-radius: 10px; overflow: hidden; background: #fff; color: #333; }
    .chart-header { padding: 8px 10px; background: #f8fbff; border-bottom: 1px solid #d0e0f0; display: flex; justify-content: space-between; align-items: center; }
    #aw-med-map { width: 100%; height: 55vh; min-height: 350px; max-height: 520px; z-index: 1; }
    .nav-warning-banner { background: #fff3cd; color: #856404; border-bottom: 1px solid #ffeeba; padding: 6px 10px; font-size: 0.68rem; font-weight: bold; text-align: center; }
    .gps-btn { background: #4673a6; color: white; border: none; padding: 5px 10px; border-radius: 5px; font-weight: bold; font-size: 0.7rem; cursor: pointer; }
    
    .polyline-measure-unicorn-node {
      width: 24px !important; height: 24px !important; margin-left: -12px !important; margin-top: -12px !important;
      border: 2px solid #ffffff !important; box-shadow: 0 0 6px rgba(0, 0, 0, 0.5) !important;
    }
    .polyline-measure-tooltip { font-size: 0.75rem !important; padding: 4px 8px !important; border-radius: 4px !important; }

    /* TAB 5: DECK LOGBOOK & YACHT DETAILS */
    .vessel-summary-banner {
      background: #0f172a; color: #38bdf8; border: 1px solid #334155; border-radius: 8px;
      padding: 10px 14px; margin-bottom: 12px; font-size: 0.85rem; line-height: 1.6; box-shadow: 0 2px 8px rgba(0,0,0,0.2);
    }
    .vessel-summary-banner strong { color: #f8fafc; font-weight: 700; }
    .vessel-summary-item { display: inline-block; margin-right: 12px; }

    .trip-meta-box { background: #f0f7ff; border: 1px solid #d0e0f0; border-radius: 6px; padding: 8px; margin-bottom: 10px; }
    .trip-meta-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
    
    .log-input-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; margin-bottom: 8px; width: 100%; }
    .log-grp { display: flex; flex-direction: column; gap: 2px; min-width: 0; width: 100%; }
    .log-grp label { font-size: 0.65rem; color: #555; font-weight: bold; text-transform: uppercase; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .log-grp input, .log-grp textarea, .log-grp select { 
      padding: 6px; border: 1px solid #ccc; border-radius: 5px; font-size: 0.8rem; background: #fcfcfc; 
      width: 100%; box-sizing: border-box; min-width: 0; 
    }
    
    .log-grp-2col { grid-column: span 2; }
    .log-grp-full { grid-column: span 3; }
    
    .log-add-btn { width: 100%; background: #10b981; color: white; border: none; padding: 8px; border-radius: 6px; font-weight: bold; font-size: 0.85rem; cursor: pointer; }
    .pdf-gen-btn { width: 100%; background: #38bdf8; color: #0f172a; border: none; padding: 10px; border-radius: 6px; font-weight: 800; font-size: 0.9rem; cursor: pointer; margin-top: 8px; box-shadow: 0 2px 8px rgba(56, 189, 248, 0.3); }
    
    #log-entries-list {
      max-height: 320px; overflow-y: auto; -webkit-overflow-scrolling: touch;
      border: 1px solid #cbd5e1; border-radius: 8px; padding: 6px; background: #f1f5f9; margin-top: 8px; margin-bottom: 12px;
    }

    .log-entry-card { background: #ffffff; border: 1px solid #cbd5e1; border-radius: 6px; padding: 8px; margin-bottom: 6px; font-size: 0.75rem; color: #333; box-shadow: 0 1px 3px rgba(0,0,0,0.05); }
    .log-entry-header { display: flex; justify-content: space-between; font-weight: bold; color: #4673a6; border-bottom: 1px solid #e2e8f0; padding-bottom: 3px; margin-bottom: 4px; }
  </style>